Skip to content

Switch logging to no longer write to root logger to avoid multiple log entries#74

Open
justus-hildebrand wants to merge 1 commit into
Johannes11833:masterfrom
justus-hildebrand:master
Open

Switch logging to no longer write to root logger to avoid multiple log entries#74
justus-hildebrand wants to merge 1 commit into
Johannes11833:masterfrom
justus-hildebrand:master

Conversation

@justus-hildebrand

Copy link
Copy Markdown

When using this project as a package in a project that also uses pythons logging API, calling e.g. logging.info() leads to multiple log entries both by the main project's logger, as well as by rclone_pythons logger. This is due to the logger being registered using logging.basicConfig(), which registers a logging handle at root level.

The python docs claim about basicConfig:

This function does nothing if the root logger already has handlers configured, unless the keyword argument force is set to True.

But because the code in rclone_python/logs.py gets 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 named rclone_python gets created with the appropriate settings and propagation set to False, 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.

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