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

Don't call logging.basicConfig() in __init__.py #659

Merged
merged 2 commits into from
Apr 13, 2023
Merged

Conversation

jwodder
Copy link
Member

@jwodder jwodder commented Apr 10, 2023

Calling logging.basicConfig() when your library is imported is incredibly rude, as it infringes upon the importing code's ability to configure the logging itself. The only time (if any) the heudiconv package should call logging.basicConfig() is in the main() function for a command-line entry point.

See also https://docs.python.org/3/howto/logging.html#configuring-logging-for-a-library.

@jwodder jwodder added the patch Increment the patch version when merged label Apr 10, 2023
@codecov
Copy link

codecov bot commented Apr 10, 2023

Codecov Report

Patch coverage: 100.00% and project coverage change: -0.01 ⚠️

Comparison is base (2c6d228) 81.48% compared to head (e526de0) 81.48%.

Additional details and impacted files
@@            Coverage Diff             @@
##           master     #659      +/-   ##
==========================================
- Coverage   81.48%   81.48%   -0.01%     
==========================================
  Files          41       41              
  Lines        3900     3899       -1     
==========================================
- Hits         3178     3177       -1     
  Misses        722      722              
Impacted Files Coverage Δ
heudiconv/__init__.py 100.00% <ø> (ø)
heudiconv/cli/run.py 91.66% <100.00%> (+0.17%) ⬆️

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

☔ View full report in Codecov by Sentry.
📢 Do you have feedback about the report comment? Let us know in this issue.

logging.basicConfig(
format="%(levelname)s: %(message)s",
level=getattr(logging, os.environ.get("HEUDICONV_LOG_LEVEL", "INFO")),
)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should I also add it to heudiconv/cli/monitor.py?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sure so we don't wonder later on. But then may be place it into some function config_logging or alike so we do not duplicate definitions.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

heh, ok then, let's just proceed for now. Not yet sure if we ever get back to monitor to make it actually used.

@yarikoptic
Copy link
Member

Thank you!

@yarikoptic yarikoptic merged commit 502bf49 into master Apr 13, 2023
@yarikoptic yarikoptic deleted the no-log-config branch April 13, 2023 18:10
@github-actions
Copy link

github-actions bot commented May 8, 2023

🚀 PR was released in v0.13.0 🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
patch Increment the patch version when merged released
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants