added LoggingEmitter

This commit is contained in:
Michael Stephens 2010-06-22 14:19:07 -04:00
parent a08771b3b1
commit 38096b3903

View File

@ -193,3 +193,22 @@ class MongoDBEmitter(Emitter):
def emit_record(self, record): def emit_record(self, record):
self.collection.insert(record) self.collection.insert(record)
class LoggingEmitter(Emitter):
""" Emitter that logs to a Python logging.Logger instance.
The msg_template will be passed the record being emitted as
a format parameter. The resulting message will get logged
at the provided level.
"""
import logging
def __init__(self, logger, msg_template, level=logging.DEBUG):
super(LoggingEmitter, self).__init__()
self.logger = logger
self.msg_template = msg_template
self.level = level
def emit_record(self, record):
self.logger.log(self.level, self.msg_template % record)