本文整理匯總了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()