Enhance logging setup#72
Open
bravier wants to merge 2 commits into
Open
Conversation
Author
|
@alexis-via if you find a moment to review this PR that would be awesome. Thanks! |
Let's use builtin `choices` parameter of `argparse` to restrict the set of values the user can choose from: https://docs.python.org/3/library/argparse.html#choices This simplifies the code a bit and doesn't change the behavior.
Calling `logging.basicConfig()` at import time is an anti-pattern for libraries: it installs a `StreamHandler` on the root logger, causing duplicate log entries in applications that configure their own logging. See Python's documentation "Configuring Logging for a Library": https://docs.python.org/3/howto/logging.html#configuring-logging-for-a-library Instead let's allow the library user to set the log level policy and move the scripts specific logging configuration to a dedicated function.
Author
|
PR updated to resolve conflicts. |
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.
scripts: Simplify log level argument handling
Let's use builtin
choicesparameter ofargparseto restrict theset of values the user can choose from:
https://docs.python.org/3/library/argparse.html#choices
This simplifies the code a bit and doesn't change the behavior.
Fix library logging
Calling
logging.basicConfig()at import time is an anti-pattern forlibraries: it installs a
StreamHandleron the root logger, causingduplicate log entries in applications that configure their own logging.
See Python's documentation "Configuring Logging for a Library":
https://docs.python.org/3/howto/logging.html#configuring-logging-for-a-library
Instead let's allow the library user to set the log level policy
and move the scripts specific logging configuration to a dedicated
function.