code: def set_log_file(
      fname=None, output_format="%(message)s", overwrite=None
  ):
      """Set the log to print to a file.
  
      Parameters
      ----------
      fname : path-like | None
          Filename of the log to print to. If None, stdout is used.
          To suppress log outputs, use set_log_level('WARNING').
      output_format : str
          Format of the output messages. See the following for examples:
  
              https://docs.python.org/dev/howto/logging.html
  
          e.g., "%(asctime)s - %(levelname)s - %(message)s".
      overwrite : bool | None
          Overwrite the log file (if it exists). Otherwise, statements
          will be appended to the log (default). None is the same as False,
          but additionally raises a warning to notify the user that log
          entries will be appended.
      """
      _remove_close_handlers(logger)
      if fname is not None:
          if op.isfile(fname) and overwrite is None:
              # Don't use warn() here because we just want to
              # emit a warnings.warn here (not logger.warn)
              warnings.warn(
                  "Log entries will be appended to the file. Use "
                  "overwrite=False to avoid this message in the "
                  "future.",
                  RuntimeWarning,
                  stacklevel=2,
              )
              overwrite = False
          mode = "w" if overwrite else "a"
          lh = logging.FileHandler(fname, mode=mode)
      else:
          """we should just be able to do:
              lh = logging.StreamHandler(sys.stdout)
          but because doctests uses some magic on stdout, we have to do this:
          """
          lh = logging.StreamHandler(WrapStdOut())
  
      lh.setFormatter(logging.Formatter(output_format))
      # actually add the stream handler
      logger.addHandler(lh)
  
imports: import contextlib
  import importlib
  import inspect
  import logging
  import os.path
  import re
  import sys
  import warnings
  from io import StringIO
  from typing import Any, Callable, TypeVar
  from decorator import FunctionMaker
  from .docs import fill_doc
label_desc: Use image node_id 4 for calling a global function with example usage: set_log_file(fname, output_format, overwrite) without return types