added LoggingEmitter
This commit is contained in:
parent
a08771b3b1
commit
38096b3903
@ -193,3 +193,22 @@ class MongoDBEmitter(Emitter):
|
||||
|
||||
def emit_record(self, 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)
|
||||
|
Loading…
Reference in New Issue
Block a user