sword wrote: > Thanks for your reply. I tried to edit the source a bit, now the > main.py looks like this: > #main.py > import logging > from logging import Filter > import a > import b > > logging.basicConfig(level=logging.DEBUG) > root = logging.getLogger() > root.addFilter(Filter("GoneWithTheWind")) #so I suppose no log msg > would pass this filter > > logger = logging.getLogger("main") > logger.debug("main process") > a.print_log() > b.print_log() > > #### > And It still prints out all the log msg. :(
Here's a little demo to explore how filtering works: $ cat demo.py import logging class Filter(logging.Filter): def filter(self, record): print "applying filter", self.name return True logging.basicConfig() loggers = [logging.getLogger(path) for path in ["", "a", "a.b"]] for logger in loggers: logger.addFilter(Filter("filter@" + logger.name)) [handler] = logging.getLogger().handlers handler.addFilter(Filter("filter@handler")) for logger in loggers: logger.critical("whatever") $ python demo.py applying filter filter@root applying filter filter@handler CRITICAL:root:whatever applying filter filter@a applying filter filter@handler CRITICAL:a:whatever applying filter filter@a.b applying filter filter@handler CRITICAL:a.b:whatever $ As you can infer from the output only the filter(s) of the original logger and of the handler(s) are applied. -- http://mail.python.org/mailman/listinfo/python-list