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

Improve logging by writing to module-level loggers instead of the root logger #152

Merged
merged 2 commits into from
Oct 7, 2024

Conversation

riley-harper
Copy link
Contributor

@riley-harper riley-harper commented Oct 7, 2024

Closes #149.

Previously we used the convenience functions on the logging module to log all of hlink's messages. But this sends all of the log messages directly to the root logger. This makes it difficult to adjust the logging level and handling specifically for hlink log messages without affecting those of other modules'.

Now we create a logger for each module, which means that each log message goes through the hlink logger before it goes to the root logger. This also gives more information about which module each log message comes from. You can now adjust the logging level just for hlink by

import logging
logging.getLogger("hlink").setLevel(logging.INFO)

This follows the setup recommended in the Logging How-To here:
https://docs.python.org/3/howto/logging.html#library-config.  This should give
users much more flexibility with how they filter and handle log messages from
hlink. And it makes the logging %(name)s attribute meaningful for hlink as
well.
@riley-harper riley-harper merged commit 5171c25 into main Oct 7, 2024
6 checks passed
@riley-harper riley-harper deleted the improve_logging branch October 7, 2024 19:17
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.

Don't log to the root logger
1 participant