This sample site_logging.py module uses the MODPYTHON Logging snippet. It assigns the ApacheLogHandler class to the main logging object, when Django is run inside MODPYTHON.
You must have the MODPYTHON Logging snippet, and name it modpython_logging.py for this to work. Apache will write to virtual host-specific logs only with Python 2.5.
Users are encouraged to change the two logging settings.
Log Level: handler.setLevel(logging.WARNING)
Log Format: logging.Formatter(...)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 | """
Django/MOD_PYTHON Site Logger
This module allows a Django/MOD_PYTHON server to log to the
current Apache virtual host.
Use the logging module as usual. Then add the log_extras()
function for the current request.
EXAMPLE
import logging
from site_logging import log_extras
logging.error(e.message, extra=log_extras(request))
"""
import logging
from modpython_logging import ApacheLogHandler, log_extras
"""
Define a Handler which writes WARNING messages or higher
to the Apache error_log.
"""
handler = ApacheLogHandler()
handler.setLevel(logging.WARNING)
formatter = logging.Formatter('%(name)-12s: %(levelname)-8s %(message)s')
handler.setFormatter(formatter)
"""
Add the Apache log handler to logging.
"""
logging.getLogger('').addHandler(handler)
|
More like this
- Template tag - list punctuation for a list of items by shapiromatron 10 months, 2 weeks ago
- JSONRequestMiddleware adds a .json() method to your HttpRequests by cdcarter 10 months, 3 weeks ago
- Serializer factory with Django Rest Framework by julio 1 year, 5 months ago
- Image compression before saving the new model / work with JPG, PNG by Schleidens 1 year, 6 months ago
- Help text hyperlinks by sa2812 1 year, 7 months ago
Comments
Please login first before commenting.