New submission from Nikolaus Rath <nikol...@rath.org>: 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." ---------- components: Library (Lib) messages: 113932 nosy: Nikratio priority: normal severity: normal status: open title: logging filter is ignored when added to root handler type: behavior versions: Python 2.6 _______________________________________ Python tracker <rep...@bugs.python.org> <http://bugs.python.org/issue9606> _______________________________________ _______________________________________________ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com