python logging filters

Grimsqueaker grimsqueaker13 at
Mon Nov 30 07:52:09 CET 2009

On Nov 30, 8:42 am, Grimsqueaker <grimsqueake... at> wrote:
> On Nov 28, 11:26 am, Vinay Sajip <vinay_sa... at> wrote:
> > On Nov 27, 1:11 pm, Grimsqueaker <grimsqueake... at> wrote:
> > > When I add a Filter to a Handler, everything works as expected (ie.
> > > all messages sent from Loggers below the Filter's level are allowed
> > > through), but when I add the Filter directly on to the Logger, only
> > > that Logger is blocked, regardless of the contents of the Filter.
> > The key thing to remember is that when a logger processes an event,
> > handlers attached to it *and all its parents* are offered the event
> > for handling. In the case where you have just one handler and it has
> > the filter attached, filtering works as you expected. By attaching the
> > filter to the root logger, you are not filtering its handler; this
> > handler is invoked for events logged to all the other loggers, and so
> > (apart from the event at the root logger) those events are not
> > filtered.
> > For some examples of filter usage, see this post:
> >
> > Regards,
> > Vinay Sajip
> OK, that makes sense, but does this mean that I am unable to block a
> logging path from one point? ie. in my example, I would have to add
> Filter( to every Logger in the 'A' path to block the A
> path from showing at my root Handler? Is there no way I can just block
> the whole 'A' path from one point? I was under the impression that
> Filters worked hierarchically and that a message would be passed up
> the chain of Loggers until it was stopped by a Filter (or its loglevel
> was not allowed).
> Thanks for your help

So would I be correct in saying that Filters apply only the the object
they are attached to and have no effect on how messages are propagated
through the logging hierarchy? If this is the case my next question
would be: How can I affect whether or not a message is propagated
further up the tree?

Sorry to post again so quickly.

More information about the Python-list mailing list