So right now i need to create and implement an extension of the Python logging module that will be used to log to our database. Basically we have several python applications(that all run in the background) that currently log to a random mishmash of text files. Which makes it almost impossible to find out if a certain application failed or not.
The problem given to me is to move said logging to text files to an oracle DB. The tables have already been defined, and where things need to be logged to but right now, im looking at adding another logging handler that will log to the DB.
I am using python 2.5.4 and cx_Oracle and the applications in general can be ether run as a service/daemon or a straight application.
I'm just mainly curious about what would be the best possible way to go about this. Few questions:
If any errors occur with cx_Oracle, where should these errors be logged to? If its down would it be best to just go and have the logger retreat to the default text file?
Awhile back we started enforcing that people use sys.stderr/stdout.write instead of print, so worst case scenario we wouldn't run into any issues with print becoming deprecated. Is there a way to seamlessly make all of the thousands of sys.std calls be piped directly into the logger, and have the logger pickup the slack?
After every logged message, should the script automatically do a commit? (there's going to be several dozen a second.)
What is the best way to implement a new handler for the logging system? Inheriting from the basic Handler class seems to be easiest.
Any ideas / suggestions would be great.
The standalone Python logging distribution (before logging was added to Python) is at http://www.red-dove.com/python_logging.html and although the logging package in Python is much more up to date, the standalone distribution contains a test directory which has a lot of useful examples of derived handler classes.