"""
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)
