oasis-open / cti-stix-elevator

OASIS Cyber Threat Intelligence (CTI) TC Open Repository: Convert STIX 1.2 XML to STIX 2.x JSON
https://stix2-elevator.readthedocs.io/en/latest/
BSD 3-Clause "New" or "Revised" License
49 stars 23 forks source link

Duplicate log entries when using stix2elevator as library #293

Closed ostefano closed 5 months ago

ostefano commented 8 months ago

The issue is due to creating the stream handler (and customizing the logger object) when one of the main modules (__init__.py and options.py) is loaded.

log = logging.getLogger(__name__)
log.propagate = False

formatter = logging.Formatter("[%(name)s] [%(levelname)-7s] [%(asctime)s] %(message)s")

# Console Handler for Elevator messages
ch = logging.StreamHandler()
ch.setFormatter(formatter)
log.addHandler(ch)

This is not correct, and while the logger object can be created at module loading time, customizations (including which formatter to use) should be moved to the script (executable) actually using the library.

For more examples see this other project which had a similar issue: https://github.com/davidonzo/apiosintDS/issues/2

ostefano commented 8 months ago

Apologies, the issue is not in this project, but in stix2validator where the following call takes place

logging.basicConfig(stream=sys.stdout, level=logging.INFO, format='%(message)s')

I can fix things by commenting out the following line inside options.py

 from stix2validator.scripts import stix2_validator

Is there any way we can remove it?

ostefano commented 5 months ago

Fix is now merged in related project 👍