python logging filters

Vinay Sajip vinay_sajip at
Sat Nov 28 10:26:28 CET 2009

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

For some examples of filter usage, see this post:


Vinay Sajip

More information about the Python-list mailing list