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

cherry-pick: avoid polluting logging's root logger (#32673) #32706

Merged
merged 1 commit into from
May 6, 2021

Conversation

iclementine
Copy link

@iclementine iclementine commented Apr 30, 2021

PR types

Bug fixes

PR changes

Others

Describe

PaddlePaddle POLLUTEs logging library by changing the config of the root logger and adding StreamHandler to it.
Logging library has a hierarchy of loggers. On top of every logger exists the root logger. Every logger's logging is also logged to its ancestors.

This can be done unexpectedly or unintentionally in two ways.

  1. logging.getLogger(), getting a logger withou passing a name or using name='root'. The root logger is returned in this case. Any settings to this logger will have a global effect;
  2. calling logging.basicConfig(*args, **kwargs). It's possible to change the formatter and other settings of the root logger in this way, but it's better not to. Also calling loggig.basicConfig without passing filename or stream will add a StreamHandler to the root logger.

If the root logger's settings are changed or stream handlers are added to the root logger when paddle is imported, all subsequent use of logging will get some unexpected behavior, redundant screen logging, undesired format, etc.

So it is better to avoid using the root logger, unless you have a good reason to do so.

details: https://stackoverflow.com/questions/24750523/disable-output-of-root-logger

This PR remove all the changes to the roor logger when paddle is imported.

avoid polluting logging's root logger
@paddle-bot-old
Copy link

Thanks for your contribution!
Please wait for the result of CI firstly. See Paddle CI Manual for details.

@paddle-bot-old
Copy link

paddle-bot-old bot commented Apr 30, 2021

✅ This PR's description meets the template requirements!
Please wait for other CI results.

@jzhang533 jzhang533 merged commit 0bb079c into PaddlePaddle:release/2.1 May 6, 2021
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.

3 participants