Re: I'm just an idiot when it comes logging

From: Vinay Sajip (vinay_sajip_at_yahoo.co.uk)
Date: 03/23/05


To: python-list@python.org
Date: Wed, 23 Mar 2005 09:18:22 +0000 (UTC)


 <olsongt <at> verizon.net> writes:

>
> I'm trying to be a good boy and use the logging module but it's
> behaving rather counter-intuitively. I've posted a simplified test
> script below.
>
> To summarize, I've set the basic config to only log root level messages
> with >= ERROR level. I've created another named logger that logs on
> info level. I've set it up so it just shows the message text without
> "INFO:: logger:" boilerplate.
>
> The way I see things, when I call otherLogger.info, it should propogate
> the message to the root logger, but the root logger should discard it
> since it is at ERROR level.
>
> Could someone explain what I'm not getting?
>
> -Grant

The way it works is: when you log to a logger, the event level is checked
against the logger. If the event should be logged (event level >= logger level)
then the event is passed to the handlers configured for that logger, and (while
the logger's propagate attribute is true - the default - passed to handlers
configured for loggers higher up the hierarchy. In your case, this inlcudes the
root logger's handlers.

Note that if you don't set a level on a logger, then the hierarchy is searched
until a level is found. That becomes the effective level for the logger.

Handlers normally process all events passed to them, but you can set a level on
a handler to get it to drop events below a certain threshold. Since you haven't
done this, you will see an INFO message appear even though the root logger's
level is set to ERROR. (This would only affect logging calls to the root logger).

Rule of thumb: Set levels on handlers only when you need them, not as common
practice. If you don't want to see info messages from otherLogger, set its level
to > INFO.

Vinay Sajip



Relevant Pages

  • RE: 0x8024402c error HELP!
    ... > descriptor. ... > logger. ...
    (microsoft.public.windowsupdate)
  • Logging with no handlers configured
    ... logger or its parents and you try to log events with that logger, ... No handlers could be found for logger ... logging or configure any handlers, the spurious message should not be ... the logging system will not give any notification. ...
    (comp.lang.python)
  • 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: Logger Handler Question
    ... has a property called 'handlers'. ... force the logger to write everything to the console as well as to any ... additional handlers that you add to the logger. ... FileHandler I defined within my program. ...
    (comp.lang.java.programmer)
  • Re: Im just an idiot when it comes logging
    ... Vinay Sajip wrote: ... you will see an INFO message appear even though the root ... root logger). ... Set levels on handlers only when you need them, ...
    (comp.lang.python)