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
- Add custom fields to the built-in Group model by jmoppel 1 month, 1 week ago
- Month / Year SelectDateWidget based on django SelectDateWidget by pierreben 4 months, 3 weeks ago
- Python Django CRUD Example Tutorial by tuts_station 5 months, 1 week ago
- Browser-native date input field by kytta 6 months, 3 weeks ago
- Generate and render HTML Table by LLyaudet 7 months ago
Comments
Please login first before commenting.