Logging with no handlers configured

From: Vinay Sajip (vinay_sajip_at_red-dove.com)
Date: 07/21/04


To: <python-list@python.org>
Date: Wed, 21 Jul 2004 22:40:56 +0100

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
printed.

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
system
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,

Vinay Sajip



Relevant Pages

  • Re: Logging
    ... record of all the handlers and then calling flush on the handler ... followed by removeHandler from the logger. ... as a feature request for logging. ... Neil Benn ...
    (comp.lang.python)
  • Re: Logging: how to suppress default output when adding handlers?
    ... But if any of my code calls a logger ... thelogging ... or remove it when I 'm setting up my handlers? ... Configure the logging system yourself before any logging call is ...
    (comp.lang.python)
  • Thanks
    ... Thanks for you assistance. ... The problem was the the logger didn't have ... any handlers. ... to do logging: ...
    (comp.lang.java.programmer)
  • "No handlers could be found for logger xxx" ?
    ... "No handlers could be found for logger xxx" on stderr ... I don't want to deal with this logging at all so far - its useless in this case anyway. ...
    (comp.lang.python)
  • Re: General question about logging concept
    ... or class to Debug to get more log messages (assuming you have more ... Also, by default the log messages include the logger info, so it's a ... Once you configure logging it's configured for the entire appdomain, ... I'm just now configuring some logging module in my web app (I'm using ...
    (microsoft.public.dotnet.framework.aspnet)