本文整理汇总了Python中logging.handlers.MemoryHandler.setFormatter方法的典型用法代码示例。如果您正苦于以下问题:Python MemoryHandler.setFormatter方法的具体用法?Python MemoryHandler.setFormatter怎么用?Python MemoryHandler.setFormatter使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类logging.handlers.MemoryHandler
的用法示例。
在下文中一共展示了MemoryHandler.setFormatter方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
# 需要导入模块: from logging.handlers import MemoryHandler [as 别名]
# 或者: from logging.handlers.MemoryHandler import setFormatter [as 别名]
def __init__(self):
memory_handler = MemoryHandler(self.MEMORY_HANDLER_SIZE)
memory_handler.setFormatter(Formatter("%(asctime)s - %(name)s - %(levelname)s - %(message)s"))
self.handlers = []
self.handlers.append(memory_handler)
self.registered_loggers = {}
示例2: make_mem_logger
# 需要导入模块: from logging.handlers import MemoryHandler [as 别名]
# 或者: from logging.handlers.MemoryHandler import setFormatter [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
示例3: make_mem_logger
# 需要导入模块: from logging.handlers import MemoryHandler [as 别名]
# 或者: from logging.handlers.MemoryHandler import setFormatter [as 别名]
def make_mem_logger(name, to_log, size=8192):
"""
Creates a memory logger to avoid writing concurrently to the main logger
"""
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: log_debug
# 需要导入模块: from logging.handlers import MemoryHandler [as 别名]
# 或者: from logging.handlers.MemoryHandler import setFormatter [as 别名]
else:
sys.stdout=sys.__stdout__ #old_stdout
sys.stderr=sys.__stderr__
#adds a stream catcher for display and a memory handler for saving
log_stream=StreamCatch()
logger=getLogger()
display_handler=StreamHandler(stream=log_stream)
display_handler.setLevel(LOGLEVEL)
display_handler.setFormatter(Formatter(LOGFORMATTER))
display_handler.name="StreamCatch"
logger.addHandler(display_handler)
memory_handler=MemoryHandler(MEMBUFFER)
memory_handler.setLevel(LOGLEVEL)
memory_handler.setFormatter(Formatter(LOGFORMATTER))
memory_handler.name="MemoryLog"
logger.addHandler(memory_handler)
log_debug("Started logging")
def make_log_file(log_path, mode='a'):
"""Points memory handler at a particular file to save the log."""
file_handler = FileHandler(filename=log_path, mode=mode)
file_handler.setLevel(LOGLEVEL)
file_handler.setFormatter(Formatter(LOGFORMATTER))
memory_handler.setTarget(file_handler)
def remove_log_file():
"""closes the log file and removes memory_handler from pointing at it"""
if memory_handler.target:
示例5: test_wording
# 需要导入模块: from logging.handlers import MemoryHandler [as 别名]
# 或者: from logging.handlers.MemoryHandler import setFormatter [as 别名]
# Original punctuation should be out of the brackets
self.positive("I am hear!", "I am [here]!")
# Drop leading and trailing spaces
self.positive(" their is ", "[there] is")
# Retain double spaces
self.positive("their is", "[there] is")
# Drop periods, commas, and semicolons
self.positive("their is.", "[there] is")
self.positive("their is,", "[there] is")
self.positive("their is;", "[there] is")
def test_wording(self):
"""Verify that wording can be generated without failing"""
self.positive(
"Their is and your don't supposed to! (blah) They think their is.")
logging.debug(self.parser.generate_wording('@@')
.encode('ascii', 'replace'))
# not implemented yet
self.assertRaises(NotImplementedError,
self.parser.generate_wording_long, '')
if __name__ == '__main__':
stream_null = StringIO()
logging.basicConfig(stream=stream_null, level=logging.DEBUG)
handler_stream = StreamHandler(stream=sys.stderr)
handler_mem = MemoryHandler(1024, target=handler_stream)
handler_mem.setLevel(logging.DEBUG)
handler_mem.setFormatter(logging.Formatter())
logging.getLogger().addHandler(handler_mem)
unittest.main()