Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

qtm_rt affects the root logger #44

Open
weeebber opened this issue Sep 9, 2024 · 0 comments
Open

qtm_rt affects the root logger #44

weeebber opened this issue Sep 9, 2024 · 0 comments

Comments

@weeebber
Copy link

weeebber commented Sep 9, 2024

Hello, when importing qtm_rt (qtm_rt/__innit__.py) it is affecting the root logger rather than the expected "qtm_rt" logger.
This therefore causes all subsequent logging calls from my program to duplicate output.

The following lines are the cause:

LEVEL = logging.DEBUG if LOG_LEVEL == "debug" else logging.INFO
logging.basicConfig(level=LEVEL, format="%(asctime)s - %(name)s - %(levelname)s - %(message)s")

Considering you are calling LOG = logging.getLogger("qtm_rt"), I dont think this was intended behaviour.

The following will correct the code to the expected behaviour:

LOG = logging.getLogger("qtm_rt")
LOG_LEVEL = os.getenv("QTM_LOGGING", "DEBUG")

# WIP - sanity check LOG_LEVEL?
# As of Python 3.2 you can use the string rather than level numeric value (i.e. DEBUG = 10)

# Configure qtm_rt logger
LOG.setLevel(LOG_LEVEL)

# Console handler with custom formatter
LOG_CONSOLE_HANDLER = logging.StreamHandler()
LOG_CONSOLE_HANDLER.setLevel(LOG_LEVEL)
LOG_CONSOLE_HANDLER.setFormatter(logging.Formatter("%(asctime)s\t%(levelno)s %(levelname)s\t%(filename)s\t%(funcName)s\t%(message)s"))
LOG.addHandler(LOG_CONSOLE_HANDLER)

And then in my program I can do the following. The below might be worth mentioning on the front page of the docs.

# Set QTM logging level to ERROR before importing
os.environ["QTM_LOGGING"] = "ERROR"
import qtm_rt
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant