'logging' module - multiple messages

David N. Welton davidw at dedasys.com
Wed Feb 12 21:33:34 EST 2003


[ CC'ing replies to me appreciated - thanks. ]

When I do something like this:


class WFLog:
    def __init__(self, name="WF"):
        self.log = logging.getLogger(name)
        f = logging.Formatter("%(name)s|%(levelname)s|%(message)s" )
        h = logging.StreamHandler()
        h.setFormatter(f)
        self.log.addHandler(h)
        self.log.setLevel(logging.DEBUG)
        self.log.debug("Logging enabled")

....

    wl = WFLog("WF")
    wl2 = WFLog("WF.SC")
    wl.debug("testing, testing, 1 2 3")
    wl2.debug("prova, prova, 1 2 3")

It appears that it prints out a copy for each logger that exists:

WF|DEBUG|Logging enabled
WF.SC|DEBUG|Logging enabled
WF.SC|DEBUG|Logging enabled
WF|DEBUG|?|testing, testing, 1 2 3
WF.SC|DEBUG|?|prova, prova, 1 2 3
WF.SC|DEBUG|?|prova, prova, 1 2 3

Which is annoying.  Any way to get it to just do one copy per log
instance?

Thanks for your time,
-- 
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