code: def redirectLoggerStreamHandlers(oldStream, newStream):
      
      for handler in list(logger.handlers): #Remove old handlers
          if handler.stream == oldStream:
              handler.close()
              logger.removeHandler(handler)
      for handler in logger.handlers: #Do not add a duplicate handler
          if handler.stream == newStream:
             return
      logger.addHandler(logging.StreamHandler(newStream))
docs: Redirect the stream of a stream handler to a different stream