Based on the accepted answer to this question: storing logger messages in a string
I would like to accomplish the same thing, but send each each log message to a list.
Many thanks
Based on the accepted answer to this question: storing logger messages in a string
I would like to accomplish the same thing, but send each each log message to a list.
Many thanks
This is already possible in stdlib by using a special-cased BufferingHandler
instance. If you use an infinite buffer, it will never flush.
>>> 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">]