This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author nikratio
Recipients nikratio
Date 2010-08-14.21:38:21
SpamBayes Score 0.00053128373
Marked as misclassified No
Message-id <1281821904.42.0.0351548448859.issue9606@psf.upfronthosting.co.za>
In-reply-to
Content
I believe the following should print only one log message, not two:

import logging
class Filter(object):
    def filter(self, record):
        return record.name == 'foo'  
logger = logging.getLogger()
formatter = logging.Formatter('%(message)s') 
handler = logging.StreamHandler()
handler.setFormatter(formatter)
logger.addFilter(Filter())
logger.addHandler(handler)
logging.getLogger('foo').warn('foo!')
logging.getLogger('bar').warn('bar!')

If the filter is added to the handler instead of the logger, everything works as expected.

If this is desired behaviour, please consider this a bug against the documentation. In that case I propose to extend the documentation of Logger.addFilter() as follows: "Note that the filter will act only on log messages that are generated by this logger, and not on messages that have been generated by descendant loggers."
History
Date User Action Args
2010-08-14 21:38:24nikratiosetrecipients: + nikratio
2010-08-14 21:38:24nikratiosetmessageid: <1281821904.42.0.0351548448859.issue9606@psf.upfronthosting.co.za>
2010-08-14 21:38:22nikratiolinkissue9606 messages
2010-08-14 21:38:21nikratiocreate