How To Cleanly Start Logging Multiple Times By Removing All Handlers With "removehandler(...)"?
During development I use the python logging module. For example, after an unhandled exception I'd like to re-run the program and freshly initialize the logging. For some reason it
Solution 1:
I think this issue is more related to your system OS and to your computer hardware characteristics. Everything works fine and prints continuously on my side
About 3 logging entries - maybe there is the same issue with flushing text in the logging
module
Note: in the part where you remove log handlers, you should make a copy of this list before iterating it. That's why you weren't clearing all logging handlers. Like this:
#Removeallhandlers:
forhandlerinlog.handlers[:]: #getridofexistingoldhandlersprint('removing handler %s'%handler)
log.removeHandler(handler)
Solution 2:
This way you remove all handlers:
logger = logging.getLogger()
while logger.hasHandlers():
logger.removeHandler(logger.handlers[0])
Post a Comment for "How To Cleanly Start Logging Multiple Times By Removing All Handlers With "removehandler(...)"?"