« »
2008-05-28Python

24

[mod_python] apache log handler

# A log handler for mod-python

  1. from mod_python import apache
  2. import logging
  3.  
  4. class ProxyLogThing:
  5.     """A proxy for default Apache logging."""
  6.  
  7.     def __init__(self):
  8.         # No need to do anything.
  9.  
  10.     def log_error(msg, lvl):
  11.         apache.log_error(msg, lvl)

  1. class ApacheLogHandler(logging.Handler):
  2.     """A handler class which sends all logging to Apache."""
  3.  
  4.     def __init__(self, ref = None):
  5.         """
  6.         Initialize the handler (does nothing)
  7.         """
  8.         logging.Handler.__init__(self)
  9.  
  10.         if ref == None:
  11.             self.ref = ProxyLogThing()
  12.         else:
  13.             self.ref = ref
  14.  
  15.         # Set up the thing
  16.         self.level_mapping = { logging.CRITICAL: apache.APLOG.CRIT,
  17.                                logging.ERROR: apache.APLOG_ERR,
  18.                                logging.WARNING: apache.APLOG_WARNING,
  19.                                logging.INFO: apache.APLOG_INFO,
  20.                                logging.debug: apache.APLOG_DEBUG }
  21.  
  22.     def emit(self, record):
  23.         """Emit a record."""
  24.         self.ref.log_error(record.msg, record.lvl)

您还可能感兴趣的内容

日志信息 »

该日志于2008-05-28 15:24由 x72 发表在Python分类下, 通告目前不可用,你可以至底部留下评论。

没有评论

发表评论 »


返回顶部