python logging module and custom handler specified in config file

Frank Aune Frank.Aune at broadpark.no
Mon Oct 15 10:15:42 EDT 2007


Hello,

I've been playing with the python logging module lately, and I manage to log 
to both stderr and MySQL database. 

What I'm wondering, is if its possible to specify the database handler in a 
config file like:

[handler_database]
class=DBHandler
level=DEBUG
formatter=database
args=('localhost', uid='root')

I've seen the log_test14.py example bundled with logging module, which 
describes the DBHandler class and I can get it working if I attach this 
handler to the root logger inside my application, but I would really like to 
do it through a config file like above. But since the logging.handlers module 
does not know about the DBHandler class, obviously this does not work.

I was thinking perhaps specifying module and classname in the class= option 
above, like class=dbhandler.DBHandler, but it will just complain that 
name 'dbhandler' is not defined.

Is this possible to archieve somehow? 

Best regards,
Frank Aune



More information about the Python-list mailing list