My first try using logger didn't work. Why?
vinay_sajip at yahoo.co.uk
Fri Jan 19 17:40:36 CET 2007
CedricCicada at gmail.com wrote:
> 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
> logger = logging.getLogger("TahChung Part 1")
> eventHandler = logging.NTEventLogHandler()
> formatter = logging.Formatter("%(message)s")
> 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:
> Rob Richardson
> RAD-CON, Inc.
Your first try didn't work because (based on your posted snippet) it
contained some errors.
The OnLAMP article was nice, but it's always best to go the the actual
Where you will see that NTEventLogHandler (described on page
http://docs.python.org/lib/node418.html) requires an initialiser
argument. Also, "setlevel" is misspelt - it should be "setLevel". The
following slightly modified version of your script puts an entry in the
NT Event Log on my machine:
import logging, logging.handlers
logger = logging.getLogger("TahChung Part 1")
eventHandler = logging.handlers.NTEventLogHandler("TahChung")
formatter = logging.Formatter("%(message)s")
logger.error("This comes from the logger object.")
More information about the Python-list