Logging with multiple loggers/handlers

Jeff Shannon jeff at ccvcorp.com
Tue Jul 6 22:41:35 CEST 2004


I'm having some difficulty getting my logging configuration set 
correctly.  I'm using a config file (copied at end of post), with the 
intent of setting several loggers which write to a combination of a 
file, stderr (for debugging), and the NT Eventlog, but I don't seem to 
be getting the right combination of handlers called.

The desired combinations are as follows:

root        - Eventlog, stderr
log02       - file, stderr
log02.log03 - file, stderr
log02.log04 - Eventlog, file, stderr

Currently, logging to stderr is working for all four loggers, but only 
log02 is being written to the logfile.  Also, log03 is writing to the 
Eventlog even though it shouldn't be reaching that handler at all.

Any suggestions as to how I could change my logconfig.ini to get the 
desired effect?  (I'm considering creating an 'init' logger off of the 
root, which would handle the Eventlog records, thus allowing me to 
propagate all the stderr records to root, but this doesn't seem like 
it'd directly affect the parts I'm having problems with...)

For reference, I'm using Python 2.2.1 and v0.4.9.2 of the logging 
package.  (Upgrading to a newer version of Python is not preferred, 
though it could be done if it'll resolve the problem, but I've gathered 
that the logging package *should* work fine with Py2.2.)

Jeff Shannon
Technician/Programmer
Credit International

----- logconf.ini -------------------------
[loggers]
keys=root,log02,log03,log04

[handlers]
keys=hand01,hand02,hand03

[formatters]
keys=form01

[logger_root]
level=NOTSET
propagate=1
channel=
parent=
qualname=(root)
handlers=hand01,hand03

[logger_log02]
level=DEBUG
propagate=0
channel=log02
parent=(root)
qualname=log02
handlers=hand02,hand03

[logger_log03]
level=DEBUG
propagate=1
channel=log03
parent=log02
qualname=log02.log03
handlers=

[logger_log04]
level=DEBUG
propagate=1
channel=log04
parent=log02
qualname=log02.log04
handlers=hand01

[handler_hand01]
class=handlers.NTEventLogHandler
level=DEBUG
formatter=form01
appname=LogTest
dllname=
logtype=Application
args=('LogTest', '', 'Application')

[handler_hand02]
class=FileHandler
level=DEBUG
formatter=form01
filename=Logs\python.log
mode=a
args=('Logs\python.log', 'a')

[handler_hand03]
class=StreamHandler
level=DEBUG
formatter=form01
stream=sys.stderr
args=(sys.stderr,)

[formatter_form01]
format=%(asctime)s %(name)s %(levelname)s %(message)s
datefmt=




More information about the Python-list mailing list