Задать вопрос

Тел: +7 965 3737 888

506

Просмотров

1

Ответов

Log Django exceptions to Apache error log in mod_wsgi

Add this to your middleware to log errors to the Apache error log when running under mod_wsgi.

Вопрос полезен? Да0/Нет0
file_3838.py(267.0б)
None

Ответы (1):

Ответadroffner:02.10.2009
Ответ полезен? Да0/Нет0

This WSGI middleware is not necessary to get mod_wsgi to use the Python logging module.

mod_wsgi (version 2.5) sends sys.stderr to the Apache2 virtual host's error_log. Therefore, one only needs to create a logging.StreamHandler() on the sys.stderr stream (the default).

Create a site_logging.py module to do this (see below). Then, just import site_logging into the settings.py on start-up.

After that, write logging statements in any module.

import logging

logging.warn('WSGI sends to the Apache2 error_log.')

MOD_WSGI site_logging.py

import logging

import sys

logger = logging.getLogger('')

logger.setLevel(logging.DEBUG)

handler = logging.StreamHandler(sys.stderr)

handler.setLevel(logging.DEBUG)

formatter = logging.Formatter('%(levelname)-8s %(message)s')

handler.setFormatter(formatter)

logger.addHandler(handler)