Trying to understand logging.Filter
Rene Pijlman
reply.in.the.newsgroup at my.address.is.invalid
Wed Jan 25 09:10:20 EST 2006
Rene Pijlman:
>3. The event is dispatched to the root logger as well,
Got it. The event is not dispatched to ancestor loggers, but to the
handlers associated with ancestor loggers (Doc: "In addition to any
handlers directly associated with a logger, all handlers associated with
all ancestors of the logger are called to dispatch the message.").
Filters of ancester loggers are not applied, therefore, but filters of
handlers of ancestor loggers are. When I add the filter to the handler
rather than the logger, it works as expected:
import logging
rootLogger = logging.getLogger()
handler = logging.FileHandler(r'C:\Scratch\SiteChecker\Sitechecker.log')
handler.addFilter(logging.Filter('ham'))
rootLogger.addHandler(handler)
rootLogger.setLevel(logging.DEBUG)
logging.getLogger('ham.eggs').info("Eat me")
logging.getLogger('spam').info("Ignore me")
logging.getLogger().info("Ignore me too")
logging.shutdown()
--
René Pijlman
Wat wil jij worden? http://www.carrieretijger.nl
More information about the Python-list
mailing list