本文整理汇总了Python中logging.handlers.MemoryHandler方法的典型用法代码示例。如果您正苦于以下问题:Python handlers.MemoryHandler方法的具体用法?Python handlers.MemoryHandler怎么用?Python handlers.MemoryHandler使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类logging.handlers
的用法示例。
在下文中一共展示了handlers.MemoryHandler方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: buffered_hdlr
# 需要导入模块: from logging import handlers [as 别名]
# 或者: from logging.handlers import MemoryHandler [as 别名]
def buffered_hdlr(target=None, capacity=4096, level="error", **kwargs):
"""A memory buffered log handler
Args:
target (obj): The target logger handler (default stdout).
capacity (int): The buffer size (default 4096).
level (string): The min event level required to flush buffer
(default: error).
Returns:
New instance of :class:`logging.handlers.MemoryHandler`
Examples:
>>> buffered_hdlr() # doctest: +ELLIPSIS
<...MemoryHandler...>
"""
target = target or logging.StreamHandler(sys.stdout)
return hdlrs.MemoryHandler(capacity, level.upper(), target)
示例2: __init__
# 需要导入模块: from logging import handlers [as 别名]
# 或者: from logging.handlers import MemoryHandler [as 别名]
def __init__(self, locale=None, target=None):
"""Initialize a TranslationHandler
:param locale: locale to use for translating messages
:param target: logging.Handler object to forward
LogRecord objects to after translation
"""
# NOTE(luisg): In order to allow this handler to be a wrapper for
# other handlers, such as a FileHandler, and still be able to
# configure it using logging.conf, this handler has to extend
# MemoryHandler because only the MemoryHandlers' logging.conf
# parsing is implemented such that it accepts a target handler.
handlers.MemoryHandler.__init__(self, capacity=0, target=target)
self.locale = locale
示例3: make_mem_logger
# 需要导入模块: from logging import handlers [as 别名]
# 或者: from logging.handlers import MemoryHandler [as 别名]
def make_mem_logger(name,to_log,size=8192):
from logging.handlers import MemoryHandler
logger=logging.getLogger(name)
hdlr=MemoryHandler(size,target=to_log)
formatter=logging.Formatter('%(message)s')
hdlr.setFormatter(formatter)
logger.addHandler(hdlr)
logger.memhandler=hdlr
logger.setLevel(logging.DEBUG)
return logger
示例4: shouldFlush
# 需要导入模块: from logging import handlers [as 别名]
# 或者: from logging.handlers import MemoryHandler [as 别名]
def shouldFlush(self, record: logging.LogRecord) -> bool:
"""
Check for record at the flushLevel or higher.
Implementation is mostly taken from `logging.handlers.MemoryHandler`
"""
return record.levelno >= self.flushLevel # type: ignore # pytype: disable=attribute-error
示例5: emit
# 需要导入模块: from logging import handlers [as 别名]
# 或者: from logging.handlers import MemoryHandler [as 别名]
def emit(self, record: logging.LogRecord) -> None:
"""
Emit a record.
Append the record. If shouldFlush() tells us to, call flush() to process
the buffer.
Implementation is taken from `logging.handlers.MemoryHandler`
"""
self._heartbeat()
if record.levelno >= self.targetLevel:
self.buffer.append(record)
if self.shouldFlush(record):
self.flush()