Login

MODPYTHON Sample Site Logging

Author:
adroffner
Posted:
August 10, 2008
Language:
Python
Version:
.96
Score:
0 (after 0 ratings)

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

  1. Template tag - list punctuation for a list of items by shapiromatron 2 months ago
  2. JSONRequestMiddleware adds a .json() method to your HttpRequests by cdcarter 2 months, 1 week ago
  3. Serializer factory with Django Rest Framework by julio 9 months, 1 week ago
  4. Image compression before saving the new model / work with JPG, PNG by Schleidens 9 months, 4 weeks ago
  5. Help text hyperlinks by sa2812 10 months, 3 weeks ago

Comments

Please login first before commenting.