python logging

David N. Welton davidw at dedasys.com
Wed Mar 19 01:40:35 CET 2003


[ Please CC replies to me - thanks ]

I'm trying to get the logging module to send multiple messages for all
sub 'classes' (ie 'foo' 'foo.bar' 'foo.bar.baz').

Someone suggested the following on this newsgroup, but it doesn't
really seem to do the trick:

class SelfishFilter(logging.Filter):
    """Filter that doesn't allow messages from children"""
    def filter(self, record):
        return self.name == record.name

Here is my code:

        self.log = logging.getLogger(name)
        f = logging.Formatter("%(name)s|%(levelname)s|%(message)s" )
        #h = logging.StreamHandler()
        h = logging.FileHandler("/var/log/wallflower.log")
        filter = SelfishFilter(name)
        h.setFormatter(f)
        self.log.addHandler(h)
        self.log.addFilter(filter)
        self.log.setLevel(logging.DEBUG)
        self.log.debug("Logging enabled")

Ideas?

Thank you,
-- 
David N. Welton
   Consulting: http://www.dedasys.com/
     Personal: http://www.dedasys.com/davidw/
Free Software: http://www.dedasys.com/freesoftware/
   Apache Tcl: http://tcl.apache.org/




More information about the Python-list mailing list