While the reference documentation for the Python 2.3 logging module probably tells me all I need to know to use the logging module, I am just not grokking how it should integrate into my system. In particular, initialising and configuring logging is a bit of a mystery.
A quick Google turned up these links:
Comments
And here is my 'quick and dirty' log function;
http://www.halfcooked.com/mt/archives/000412.html
I just threw this together:
http://www.mechanicalcat.net/richard/log/index_html
hope it helps.
Andy, Richard,
Thanks for the tips!
a
>>> logging.config.fileConfig('log.ini')
>>> logging.info('this is a log message to the root logger')
Unfortunately, the logging config file is quite horrible :-(
fyi, if you're working with a version of python older than v2.3, you can download the logging module here and add it to your python installation:
http://www.red-dove.com/python_logging.html#download
Alan - I never meant to imply you were comparing Python's docs to PHP, but I have heard it from people in the 'real' world outside of the weblog community.
What did you finally settle on for your logging configuration for your test enviroment?
All of my configuration files are placed in /etc/<myappname> by a distutils setup.py file. When my system comes up, I use ZConfig to parse /etc/myapp/app.conf. I just toss the ZConfig object to logging and get everything configured in one shot on startup.
Victor,
No problem, I was just being a bit cheeky back :)
Thanks for taking the time to set things straight though.
Since I don't quite know how sophisticated logging will need to be yet, I'm just putting an "import logconfig" at the top of each of my modules that does logging. The logconfig module is just ten lines of setup code - remarkably similar to the manual. Unit tests that want to turn on more logging can do so.
If I find the app need more sophisticated setup in the future, I'll still be able to drop it in. ZObject looks cool, but I'll have to put it on my list of "stuff to look at, eventually".