本文整理汇总了Python中logging.handlers.BufferingHandler.setLevel方法的典型用法代码示例。如果您正苦于以下问题:Python BufferingHandler.setLevel方法的具体用法?Python BufferingHandler.setLevel怎么用?Python BufferingHandler.setLevel使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类logging.handlers.BufferingHandler
的用法示例。
在下文中一共展示了BufferingHandler.setLevel方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: DebugDumper
# 需要导入模块: from logging.handlers import BufferingHandler [as 别名]
# 或者: from logging.handlers.BufferingHandler import setLevel [as 别名]
class DebugDumper(BCRelay):
def __init__(self, *argz, **kwz):
super(DebugDumper, self).__init__(*argz, **kwz)
# Simple buffered handler that never triggers flush
self.handler = BufferingHandler(capacity=self.conf.capacity)
self.buffer = self.handler.buffer = deque(maxlen=self.handler.capacity)
self.handler.capacity += 1
self.handler.setLevel(self.conf.level)
self.handler.setFormatter(
logging.Formatter(self.conf.format, self.conf.datefmt) )
logging.root.addHandler(self.handler)
# Signal log-dump interface
if self.conf.signal and isinstance(self.conf.signal, str):
signum = getattr(signal, self.conf.signal, None)
if not signum: signum = getattr(signal, 'SIG{}'.format(self.conf.signal), None)
self.conf.signal = signum
if self.conf.signal:
def signal_handler(sig, frm):
# Supress buffering of re-issued messages
self.handler._emit, self.handler.emit = self.handler.emit, lambda *a, **k: None
for msg in list(self.buffer): log.fatal(self.handler.format(msg))
self.handler.emit = self.handler._emit
signal.signal(self.conf.signal, signal_handler)
def dispatch(self, msg, source=None):
if msg != self.conf.command:
log.noise('Ignoring unknown command: {!r} (source: {})'.format(msg, source))
return
if not self.conf.direct: source = None # reply to whatever destination channel
msg = '\n'.join(it.imap(self.handler.format, list(self.buffer)))
reactor.callLater( 0, self.interface.dispatch,
msg, source=self, user=source, direct=True )