code: def redirect_logging(tqdm_obj, logger=logging.getLogger()):
    
    # remove current handler
    assert(len(logger.handlers) == 1)
    prev_handler = logger.handlers[0]
    logger.removeHandler(prev_handler)
  
    # add tqdm handler
    tqdm_handler = TqdmLoggingHandler(tqdm_obj)
    if prev_handler.formatter is not None:
      tqdm_handler.setFormatter(prev_handler.formatter)
    logger.addHandler(tqdm_handler)
  
    try:
      yield
    finally:
      # restore handler
      logger.removeHandler(tqdm_handler)
      logger.addHandler(prev_handler)
docs: Context manager to redirect logging to a TqdmLoggingHandler object and then restore the original.