[Python-Dev] Logging with no handlers configured
vinay_sajip at red-dove.com
Wed Jul 21 23:40:56 CEST 2004
Currently, if the logging module is used with no handlers configured for a
logger or its parents and you try to log events with that logger, a single
message is printed to sys.stderr:
No handlers could be found for logger <logger name>
It has been suggested that this puts out a spurious message when, for
whatever reason, a developer intentionally does not configure any
handlers. A good use case for this is when writing a library component - the
library may happily log events, and if the application using it doesn't use
logging or configure any handlers, the spurious message should not be
However, the message is there for a reason - to help spot logging
configuration problems, which can be a bit hard to debug if the logging
doesn't output anything at all.
To meet both requirements, I propose that a change be made as follows: the
missing handlers situation will only be notified if raiseExceptions is set.
The current default value will cause the missing handlers situation to be
notified (once) - i.e. the default behaviour will remain as is. If
raiseExceptions is unset, the logging system will not give any notification.
Another question - exactly how to make the notification - also needs
resolving; is printing a message to sys.stderr better or worse than raising
an exception? I could create a new LoggingConfigurationException, an
instance of which would be thrown instead of printing the message. However,
this could break existing applications, so I'm canvassing opinions on this.
All feedback gratefully received,
More information about the Python-Dev