My first try using logger didn't work. Why?

CedricCicada at gmail.com CedricCicada at gmail.com
Fri Jan 19 16:48:54 CET 2007


Greetings!

I want to write messages into the Windows event log.  I found
sevicemanager, but the source is always "Python Service", and I'd like
to be a bit more descriptive.  Poking around on the Internet revealed
the existence of the logging module.  It seems to have easily
understood methods with the power I need.  So I tried it.  Here's my
attempt:

            logger = logging.getLogger("TahChung Part 1")
            logger.setLevel(logging.INFO)
            eventHandler = logging.NTEventLogHandler()
            eventHandler.setlevel(logging.INFO)
            formatter = logging.Formatter("%(message)s")
            eventHandler.setFormatter(formatter)

            logger.addHandler(eventHandler)
            logger.error("This comes from the logger object.")

I get no error messages from this, but I also don't get anything in my
event log.  What am I doing wrong?

By the way, my source of instructions for how to do this was:
http://www.onlamp.com/pub/a/python/2005/06/02/logging.html

Rob Richardson
RAD-CON, Inc.




More information about the Python-list mailing list