本文整理汇总了Python中logging.handlers.BufferingHandler.setFormatter方法的典型用法代码示例。如果您正苦于以下问题:Python BufferingHandler.setFormatter方法的具体用法?Python BufferingHandler.setFormatter怎么用?Python BufferingHandler.setFormatter使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类logging.handlers.BufferingHandler
的用法示例。
在下文中一共展示了BufferingHandler.setFormatter方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: DebugDumper
# 需要导入模块: from logging.handlers import BufferingHandler [as 别名]
# 或者: from logging.handlers.BufferingHandler import setFormatter [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 )
示例2: create_session_logger
# 需要导入模块: from logging.handlers import BufferingHandler [as 别名]
# 或者: from logging.handlers.BufferingHandler import setFormatter [as 别名]
def create_session_logger(format="CPC"):
logger = logging.getLogger("")
try:
logger.addHandler(HANDLER["%s-buffer" % format])
except KeyError:
_formatter = logging.Formatter(format)
handl = BufferingHandler(10000)
handl.setFormatter(_formatter)
logger.addHandler(handl)
logger.setLevel(logging.INFO)
return logger
示例3: create_logger
# 需要导入模块: from logging.handlers import BufferingHandler [as 别名]
# 或者: from logging.handlers.BufferingHandler import setFormatter [as 别名]
def create_logger(filename, base_dir):
"""
Creates a logger with a given filename.
:param filename: File name for the log
:return: A logger class.
"""
logger = logging.getLogger("")
logfile_name = base_dir + filename
handler = logging.FileHandler(logfile_name)
base_formatter = logging.Formatter(
"%(asctime)s %(name)s:%(levelname)s %(message)s")
cpc = ('%(asctime)s %(name)s:%(levelname)s '
'[%(client)s,%(path)s,%(cid)s] %(message)s')
handler.setFormatter(base_formatter)
logger.addHandler(handler)
logger.setLevel(logging.DEBUG)
_formatter = logging.Formatter(cpc)
fil_handler = logging.FileHandler(logfile_name)
fil_handler.setFormatter(_formatter)
buf_handler = BufferingHandler(10000)
buf_handler.setFormatter(_formatter)
return logger
示例4: create_logger
# 需要导入模块: from logging.handlers import BufferingHandler [as 别名]
# 或者: from logging.handlers.BufferingHandler import setFormatter [as 别名]
def create_logger(filename):
"""
Creates a logger with a given filename.
:param filename: File name for the log
:return: A logger class.
"""
logger = logging.getLogger("")
LOGFILE_NAME = filename
hdlr = logging.FileHandler(LOGFILE_NAME)
base_formatter = logging.Formatter(
"%(asctime)s %(name)s:%(levelname)s %(message)s")
CPC = ('%(asctime)s %(name)s:%(levelname)s '
'[%(client)s,%(path)s,%(cid)s] %(message)s')
cpc_formatter = logging.Formatter(CPC)
hdlr.setFormatter(base_formatter)
logger.addHandler(hdlr)
logger.setLevel(logging.DEBUG)
_formatter = logging.Formatter(CPC)
fil_handl = logging.FileHandler(LOGFILE_NAME)
fil_handl.setFormatter(_formatter)
buf_handl = BufferingHandler(10000)
buf_handl.setFormatter(_formatter)
return logger
示例5: BufferingHandler
# 需要导入模块: from logging.handlers import BufferingHandler [as 别名]
# 或者: from logging.handlers.BufferingHandler import setFormatter [as 别名]
base_formatter = logging.Formatter(
"%(asctime)s %(name)s:%(levelname)s %(message)s")
CPC = '%(asctime)s %(name)s:%(levelname)s [%(client)s,%(path)s,%(cid)s] %(message)s'
cpc_formatter = logging.Formatter(CPC)
hdlr.setFormatter(base_formatter)
LOGGER.addHandler(hdlr)
LOGGER.setLevel(logging.DEBUG)
_formatter = logging.Formatter(CPC)
fil_handl = logging.FileHandler(LOGFILE_NAME)
fil_handl.setFormatter(_formatter)
buf_handl = BufferingHandler(10000)
buf_handl.setFormatter(_formatter)
HANDLER = {"CPC-file": fil_handl, "CPC-buffer": buf_handl}
ACTIVE_HANDLER = "BASE"
URLMAP = {}
NAME = "pyoic"
OAS = None
PASSWD = [("diana", "krall"), ("babs", "howes"), ("upper", "crust")]
#noinspection PyUnusedLocal
def devnull(txt):
pass