@contextmanager
def no_handlers_for_logger(name=None):
 log = logging.getLogger(name)
 old_handlers = log.handlers
 old_propagate = log.propagate
 log.handlers = [NullHandler()]
 try:
  (yield)
 finally:
  if old_handlers:
   log.handlers = old_handlers
  else:
   log.propagate = old_propagate

@ contextmanager def no_handlers_for_logger ( name = None ) : log = logging . getLogger ( name ) old_handlers = log . handlers old_propagate = log . propagate log . handlers = [ NullHandler ( ) ] try : ( yield ) finally : if old_handlers : log . handlers = old_handlers else : log . propagate = old_propagate
temporarily remove handlers all handlers from a logger .