code: def setup_logging(name, output_dir=None, rank=0):
      """
      Setup various logging streams: stdout and file handlers.
  
      For file handlers, we only setup for the master gpu.
      """
      # get the filename if we want to log to the file as well
      log_filename = None
      if output_dir:
          makedir(output_dir)
          if rank == 0:
              log_filename = f"{output_dir}/log.txt"
  
      logger = logging.getLogger(name)
      logger.setLevel(logging.DEBUG)
  
      # create formatter
      FORMAT = "%(levelname)s %(asctime)s %(filename)s:%(lineno)4d: %(message)s"
      formatter = logging.Formatter(FORMAT)
  
      # clean up any pre-existing handlers
      for h in logger.handlers:
          logger.removeHandler(h)
      logger.root.handlers = []
  
      # setup the console handler
      console_handler = logging.StreamHandler(sys.stdout)
      console_handler.setLevel(logging.DEBUG)
      console_handler.setFormatter(formatter)
      logger.addHandler(console_handler)
  
      # we log to file as well if user wants
      if log_filename and rank == 0:
          file_handler = logging.StreamHandler(
              _cached_log_stream(log_filename)
          )
          file_handler.setLevel(logging.DEBUG)
          file_handler.setFormatter(formatter)
          logger.addHandler(file_handler)
  
      logging.root = logger
  
file_path: vissl/vissl/utils/logger.py
imports: import atexit
  import functools
  import logging
  import subprocess
  import sys
  from iopath.common.file_io import g_pathmgr
  from vissl.utils.io import makedir
label_desc: Use image node_id 1 for calling a global function with example usage: setup_logging(name, output_dir, rank) without return types