[mod_python] apache log handler
# A log handler for mod-python
- from mod_python import apache
- import logging
- class ProxyLogThing:
- """A proxy for default Apache logging."""
- def __init__(self):
- # No need to do anything.
- def log_error(msg, lvl):
- apache.log_error(msg, lvl)
- class ApacheLogHandler(logging.Handler):
- """A handler class which sends all logging to Apache."""
- def __init__(self, ref = None):
- """
- Initialize the handler (does nothing)
- """
- logging.Handler.__init__(self)
- if ref == None:
- self.ref = ProxyLogThing()
- else:
- self.ref = ref
- # Set up the thing
- self.level_mapping = { logging.CRITICAL: apache.APLOG.CRIT,
- logging.ERROR: apache.APLOG_ERR,
- logging.WARNING: apache.APLOG_WARNING,
- logging.INFO: apache.APLOG_INFO,
- logging.debug: apache.APLOG_DEBUG }
- def emit(self, record):
- """Emit a record."""
- self.ref.log_error(record.msg, record.lvl)
没有评论▼