答案 0 :(得分:0)
使用特殊情况的BufferingHandler
实例在stdlib中已经可以实现。如果使用无限缓冲区,则永远不会刷新。
>>> myhandler = logging.handlers.BufferingHandler(capacity=float('inf'))
>>> logging.basicConfig(handlers=[myhandler])
>>> logging.warning("uh-oh")
>>> logging.error("boom")
>>> myhandler.buffer
[<LogRecord: root, 30, <ipython-input-11-feb6b3c2bc6f>, 1, "uh-oh">,
<LogRecord: root, 40, <ipython-input-12-fd4144525168>, 1, "boom">]