0

任何人都可以帮助我添加内存处理程序,缓冲处理程序以使我的程序最佳(刷新缓冲内存)。

import logging
logger = logging.getLogger()
logger.setLevel(logging.DEBUG)#we can set deug_level at logger level also

formatter = logging.Formatter('%(asctime)s - %(levelname)s - %(message)s')

ch = logging.StreamHandler()
ch.setLevel(logging.DEBUG)
ch.setFormatter(formatter)
logger.addHandler(ch)

logger.debug('This is a test log message.')
4

1 回答 1

4

创建内存处理程序就像创建流处理程序一样,将流处理程序作为目标传递:

streamhandler = logging.StreamHandler()
streamhandler.setFormatter(formatter)
memoryhandler = logging.handlers.MemoryHandler(1024*10, logging.DEBUG, streamhandler)
logger.addHandler(memoryhandler)

不要使用logger.addHandler.

于 2012-10-21T14:52:07.487 回答