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

Logging should not be done with the root logger #123

Open
scarere opened this issue Jul 12, 2024 · 0 comments
Open

Logging should not be done with the root logger #123

scarere opened this issue Jul 12, 2024 · 0 comments

Comments

@scarere
Copy link

scarere commented Jul 12, 2024

Currently both the MultiThreadedAugmenter and NonDetMultiThreadedAugmenter classes use the root logger to print logs to the console. Calling logging.debug() implicitly creates a new stream handler for the root logger. This is problematic in cases where the user is already using their own logger with its own stream handler. Messages are printed once by the user's logger, and then echoed by the root logger. The solution is simply to create a new logger for the batchgenerators package, and then use that logger to print relevant messages to stdout. For example a logger.py file could contain:

import logging
logger = logging.getLogger('batchgenerators')
handler = logging.StreamHandler()
handler.setLevel(logging.DEBUG)
logger.addHandler(handler)
log = logger.log

Then to print logs to stdout in other files such as multi_threaded_augmenter.py

from logger import log
from logging import INFO, DEBUG

# Something happens in the code
log('A message about what happened')
log(INFO, 'This is an info message instead of default DEBUG message')
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