python logging filters

Grimsqueaker grimsqueaker13 at gmail.com
Mon Nov 30 01:42:50 EST 2009


On Nov 28, 11:26 am, Vinay Sajip <vinay_sa... at yahoo.co.uk> wrote:
> On Nov 27, 1:11 pm, Grimsqueaker <grimsqueake... at gmail.com> 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:
>
> http://groups.google.com/group/comp.lang.python/msg/2eb4cf8f879c6451
>
> 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(loggerB.name) 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



More information about the Python-list mailing list