@contextmanager
def pending_logging():
 logger = logging.getLogger()
 memhandler = MemoryHandler()
 try:
  handlers = []
  for handler in logger.handlers[:]:
   logger.removeHandler(handler)
   handlers.append(handler)
  logger.addHandler(memhandler)
  (yield memhandler)
 finally:
  logger.removeHandler(memhandler)
  for handler in handlers:
   logger.addHandler(handler)
  memhandler.flushTo(logger)

@ contextmanager def pending_logging ( ) : logger = logging . getLogger ( ) memhandler = MemoryHandler ( ) try : handlers = [ ] for handler in logger . handlers [ : ] : logger . removeHandler ( handler ) handlers . append ( handler ) logger . addHandler ( memhandler ) ( yield memhandler ) finally : logger . removeHandler ( memhandler ) for handler in handlers : logger . addHandler ( handler ) memhandler . flushTo ( logger )
contextmanager to pend logging all logs temporary .