Logging Middleware

This is a simple Logging Middleware that uses the python logging functions.

Simply drop this snippet in a file in your project such as logmw.py (don't try to call it logging.py though), then add the class to MIDDLEWARE_CLASSES in your settings file. (for instance, 'mysite.logmw.LoggingMiddleware')

Updated 8/25/08: added PhonyLogger class that swallows log messages when logging is disabled, so code doesn't have to care if it's on or not (thanks to goodness for suggesting the idea, though I missed it before)

Comments

Hmm, I'm not sure I fully understand how people use this. If I set LOG_ENABLED, then all my logging statements now cause errors? I modified the code a little bit to stick a class with empty methods in request.logger. So something like: