Switch logging to no longer write to root logger to avoid multiple log entries#74
Open
justus-hildebrand wants to merge 1 commit into
Open
Switch logging to no longer write to root logger to avoid multiple log entries#74justus-hildebrand wants to merge 1 commit into
justus-hildebrand wants to merge 1 commit into
Conversation
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.
When using this project as a package in a project that also uses pythons
loggingAPI, calling e.g.logging.info()leads to multiple log entries both by the main project's logger, as well as byrclone_pythons logger. This is due to the logger being registered usinglogging.basicConfig(), which registers a logging handle at root level.The python docs claim about
basicConfig:But because the code in
rclone_python/logs.pygets executed during package import, this is quite likely to not be the case when importing rclone at the top of a file.This PR proposes a low profile fix: Instead of registering a logger at root level using
basicConfig(), which comes with the issue named above, a logger namedrclone_pythongets created with the appropriate settings and propagation set toFalse, so the root logger of any importing script does not get spammed by this package's outputs and this package retains control over its own outputs. The rest of the package's interface remains unchanged.