New submission from David Escott: The documentation suggests using a MemoryHandler object to buffer log messages and conditionally output them. https://docs.python.org/3/howto/logging-cookbook.html#buffering-logging-messages-and-outputting-them-conditionally
However the documentation does not make clear that this only works because of the call to super(MemoryHandler, handler).flush() prior to logger.removeHandler(handler). A direct call to handler.flush(), or simply leaving the handler unflushed until process shutdown will result in the messages still being printed, when the MemoryHandler calls self.flush() during its shutdown routines. To be honest this behavior of MemoryHandler doesn't make much sense to me, since the MemoryHandler is in fact flushing when flush_level has not been satisfied. I would suggest adding an option to the MemoryHandler "flush_on_close" defaulting to True, and then simply constructing the MemoryHandler with that option set to False. That would not affect the existing users of the handler, but it would result in a tool which would actually match the only example I have come across of a MemoryHandler in use online. ---------- components: Library (Lib) messages: 261772 nosy: David Escott priority: normal severity: normal status: open title: logging.handlers.MemoryHandler flushes on shutdown but not removal type: behavior versions: Python 3.5 _______________________________________ Python tracker <rep...@bugs.python.org> <http://bugs.python.org/issue26559> _______________________________________ _______________________________________________ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com