<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def redirect_logging(tqdm_obj, logger=logging.getLogger()):
 """ Context manager to redirect logging to a TqdmLoggingHandler object and then restore the original. """

  # 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)