简体   繁体   中英

Logging configuration with disable_existing_loggers = false

The Python logging tutorials imply that disable_existing_loggers should be true, but I am having trouble with that configuration. What I think is happening is that the __main__ module imports various pieces of the application which setup loggers (during import) before the logging system can be configured. Those loggers get disabled at configuration time and don't produce the expected output.

I have several hundred files of legacy source code and over a dozen __main__ module entry points. Removing all the toplevel calls to setup individual loggers seems like a difficult cat herding problem. Re-working every __main__ module might be possible, but simply flipping disable_existing_loggers to be false (in.json) is much easier and seems to work. I don't think anyone is doing anything extremely tricky with the loggers and I have not seen issues with limited testing of the patch.

What are the consequences and pitfalls of this approach? What needs to be done to make it a reliable solution?

I don't think the docs imply that it should be True - they just state that the default value is True for backwards compatibility, ie so as not to break existing (older) code. It's fine to pass False for disable_existing_loggers , and lots of people do it. Of course, be sure that you definitely want existing loggers to be left enabled.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM