[issue17749] root logging functions break logger configuration

Vinay Sajip report at bugs.python.org
Tue Apr 16 16:07:27 CEST 2013


Vinay Sajip added the comment:

No, this behaviour is as expected. The sequence of events:

1. You call setup_logging(), which creates a logger with level DEBUG, and add a file handler to it.
2. You import m2, which calls logging.info(), which adds a handler to the root logger (via basicConfig() - see the documentation note just below the documentation for the logging.log function). However, since the root logger's default level is WARNING, the logging.info() call produces no output.
3. You call logger.info(), which calls your file handler as expected, then calls the handlers of ancestor loggers (as documented - see 

http://docs.python.org/2.7/howto/logging.html#logging-flow

for more info). This results in the message being output to file (via the handler you added in setup_logging) and to console (via the handler you added to the root logger in logging.info() in m2.py).

Note that if you add a line

logger.propagate = False

in setup_logging before you return the logger, then the root logger's handler isn't called. However, the general best practice is to let propagation do the work (i.e. don't set it to False unless you have very specific needs).

----------
resolution:  -> invalid
status: open -> closed

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue17749>
_______________________________________


More information about the Python-bugs-list mailing list