Log through named module loggers instead of the root logger - #140
Open
asaraog wants to merge 1 commit into
Open
Conversation
The augmenters called module-level logging.debug()/logging.error(), which go to the root logger. The first such call runs basicConfig() and installs a StreamHandler on root, so an application with its own logger and handler sees every record twice. Take logging.getLogger(__name__) in each module and log through it. No handler is attached: a library adding one takes the choice of destination and format away from the application. Fixes MIC-DKFZ#123
Author
|
Full test suite passes on this branch: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #123.
MultiThreadedAugmenterandNonDetMultiThreadedAugmenterlog through the module-levellogging.debug()/logging.error(), which go to the root logger. The first such call runsbasicConfig()and installs aStreamHandleron root as a side effect, so an application with its own logger and handler sees every record twice — once from its own handler, once echoed from root:Each module now takes
logger = logging.getLogger(__name__)and the ninelogging.*calls becomelogger.*.One deviation from the suggestion in the issue: it proposes attaching a
StreamHandlerinside the package. I have deliberately not done that — a library adding its own handler is the same class of problem, just quieter, and it takes the choice of destination and format away from the application. With named loggers and no handler, records propagate to whatever the application configured, and anyone who wants batchgenerators output specifically can reach for it by name:No behaviour change for callers who never configure logging:
logging.lastResortstill prints WARNING and above to stderr.