Skip to content

Enhance logging setup#72

Open
bravier wants to merge 2 commits into
akretion:masterfrom
bravier:better-logging
Open

Enhance logging setup#72
bravier wants to merge 2 commits into
akretion:masterfrom
bravier:better-logging

Conversation

@bravier
Copy link
Copy Markdown

@bravier bravier commented Apr 23, 2026

scripts: Simplify log level argument handling

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.


Fix library logging

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.

@bravier
Copy link
Copy Markdown
Author

bravier commented May 6, 2026

@alexis-via if you find a moment to review this PR that would be awesome. Thanks!

bravier added 2 commits June 2, 2026 14:55
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.
@bravier
Copy link
Copy Markdown
Author

bravier commented Jun 2, 2026

PR updated to resolve conflicts.

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

Successfully merging this pull request may close these issues.

1 participant