Message113932
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." |
|
Date |
User |
Action |
Args |
2010-08-14 21:38:24 | nikratio | set | recipients:
+ nikratio |
2010-08-14 21:38:24 | nikratio | set | messageid: <1281821904.42.0.0351548448859.issue9606@psf.upfronthosting.co.za> |
2010-08-14 21:38:22 | nikratio | link | issue9606 messages |
2010-08-14 21:38:21 | nikratio | create | |
|