docs: def tee_log(tee_file: TextIO, loglevel: int) -> None:
      """
      Context manager to add a file output stream to our logging system.
  
      Args:
          tee_file: file-like object to write to
          loglevel: log level (e.g. ``logging.DEBUG``) to use for this stream
  
      """
      handler = get_monochrome_handler(stream=tee_file)
      handler.setLevel(loglevel)
      rootlogger = logging.getLogger()
      rootlogger.addHandler(handler)
      # Tee the main stdout/stderr as required.
      with TeeContextManager(tee_file, capture_stdout=True):
          with TeeContextManager(tee_file, capture_stderr=True):
              try:
                  yield
              except Exception:
                  # We catch this so that the exception also goes to
                  # the log.
                  exc_type, exc_value, exc_traceback = sys.exc_info()
                  lines = traceback.format_exception(exc_type, exc_value,
                                                     exc_traceback)
                  log.critical("\n" + "".join(lines))
                  raise