Nic Ferrier
nferrier at tapsellferrier.co.uk
Sun Oct 16 20:33:47 EDT 2005
Nic Ferrier <nferrier at tapsellferrier.co.uk> writes: > PS for what it's worth here's mine: Whoops! Here's an altered one that actually works: # 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 logging level self.level_mapping = { } self.level_mapping[logging.ERROR] = apache.APLOG_ERR self.level_mapping[logging.WARNING] = apache.APLOG_WARNING self.level_mapping[logging.INFO] = apache.APLOG_INFO self.level_mapping[logging.debug] = apache.APLOG_DEBUG def emit(self, record): """Emit a record.""" self.ref.log_error(record.msg, record.lvl) # End
|