Login

MODPYTHON Sample Site Logging

Author:
adroffner
Posted:
August 10, 2008
Language:
Python
Version:
.96
Tags:
logging mdpython
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. Logging solution for mod_python/FCGI by mikeivanov 7 years, 10 months ago
  2. Twisted protocol for receiving logging module messages over a socket by afternoon 6 years, 9 months ago
  3. SQL Log To Console Middleware by davepeck 5 years, 11 months ago
  4. Logging Middleware by Magus 7 years, 10 months ago
  5. SQL Log Middleware - with multiple databases by guglielmocelata 4 years, 5 months ago

Comments

Please login first before commenting.