Our Python logging system is pretty simple in concept. I wanted to use a database so I wrote a “Database_Handler” class that can be used with regular (and excellent) Python logging.Logger objects. There’s lots of pre-built handler classes in the standard library to use but none that fires into a databases (in Python 2.6, anyway). My class is a subclass of logging.Handler, and overrides the “emit” function to take the log record passed in, pulls data off it and posts it to our MS SQL database. Each “tool” we have creates a logger object for itself and adds our Database_Handler, just like you would with a regular handler.
At that point we just add one-line events like these, where desired:
log.info( ‘Tool X launched’ )
log.info( ‘Whatever process took X seconds’ )
log.warning( ‘Something is not right’ )
log.error( ‘ERROR: Help me!’ )
… That kind of thing. You could also put calls like that inside a decorator, of course.
I’m glossing over some stuff, but that’s the gist of it. I’d be glad to go into the gory details if anyone likes.