selective logger disable/enable

Vinay Sajip vinay_sajip at
Fri Jan 19 12:02:44 CET 2007

Gary Jefferson wrote:

> Suppose I have 3 modules that belong to a project, 'A', 'A.a' and 'B',
> and each module has its own logger, created with:
> module1logger = logging.getLogger('project.A')
> and
> module2logger = logging.getLogger('project.A.a')
> and
> module3logger = logging.getLogger('project.B')
> And I want to selectively enable/disable these, per module (for
> example, I only want logging from A and A.a, or just from B, etc).  It
> seems like logging.Filter is supposed to let me do this, but I can't
> see how to apply it globally.  Is there really no other way that to add
> a addFilter(filter) call to each of these loggers individually?

The documentation for Logger - see

- shows that there are addFilter() and removeFilter() methods on the
Logger class which you can use to add or remove filters from individual
Logger instances. From the above page (entitled "14.5.1 Logger

    Adds the specified filter filt to this logger.

    Removes the specified filter filt from this logger.

The parent section of Section 14.5.1, which is Section 14.5, was the
first search result when I just searched Google for "python logging".

Best regards,

Vinay Sajip

More information about the Python-list mailing list