code: def setup_logger(
      output: str = None,
      color: bool = True,
      name: str = "mmf",
      disable: bool = False,
      clear_handlers=True,
      *args,
      **kwargs,
  ):
      """
      Initialize the MMF logger and set its verbosity level to "INFO".
      Outside libraries shouldn't call this in case they have set there
      own logging handlers and setup. If they do, and don't want to
      clear handlers, pass clear_handlers options.
  
      The initial version of this function was taken from D2 and adapted
      for MMF.
  
      Args:
          output (str): a file name or a directory to save log.
              If ends with ".txt" or ".log", assumed to be a file name.
              Default: Saved to file <save_dir/logs/log_[timestamp].txt>
          color (bool): If false, won't log colored logs. Default: true
          name (str): the root module name of this logger. Defaults to "mmf".
          clear_handlers (bool): If false, won't clear existing handlers.
  
      Returns:
          logging.Logger: a logger
      """
      if disable:
          return None
      logger = logging.getLogger(name)
      logger.propagate = False
  
      logging.captureWarnings(True)
      warnings_logger = logging.getLogger("py.warnings")
  
      plain_formatter = logging.Formatter(
          "%(asctime)s | %(levelname)s | %(name)s : %(message)s",
          datefmt="%Y-%m-%dT%H:%M:%S",
      )
  
      distributed_rank = get_rank()
      handlers = []
  
      config = registry.get("config")
      if config:
          logging_level = (
              config.get("training", {})
              .get("logger_level", "info")
              .upper()
          )
      else:
          logging_level = logging.INFO
  
      if distributed_rank == 0:
          logger.setLevel(logging_level)
          ch = logging.StreamHandler(stream=sys.stdout)
          ch.setLevel(logging_level)
          if color:
              formatter = ColorfulFormatter(
                  colored("%(asctime)s | %(name)s: ", "green")
                  + "%(message)s",
                  datefmt="%Y-%m-%dT%H:%M:%S",
              )
          else:
              formatter = plain_formatter
          ch.setFormatter(formatter)
          logger.addHandler(ch)
          warnings_logger.addHandler(ch)
          handlers.append(ch)
  
      # file logging: all workers
      if output is None:
          output = setup_output_folder()
  
      if output is not None:
          if output.endswith(".txt") or output.endswith(".log"):
              filename = output
          else:
              filename = os.path.join(output, "train.log")
          if distributed_rank > 0:
              filename = filename + f".rank{distributed_rank}"
          PathManager.mkdirs(os.path.dirname(filename))
  
          fh = logging.StreamHandler(_cached_log_stream(filename))
          fh.setLevel(logging_level)
          fh.setFormatter(plain_formatter)
          logger.addHandler(fh)
          warnings_logger.addHandler(fh)
          handlers.append(fh)
  
          # Slurm/FB output, only log the main process
          if "train.log" not in filename and distributed_rank == 0:
              save_dir = get_mmf_env(key="save_dir")
              filename = os.path.join(save_dir, "train.log")
              sh = logging.StreamHandler(_cached_log_stream(filename))
              sh.setLevel(logging_level)
              sh.setFormatter(plain_formatter)
              logger.addHandler(sh)
              warnings_logger.addHandler(sh)
              handlers.append(sh)
  
          logger.info(f"Logging to: {filename}")
  
      # Remove existing handlers to add MMF specific handlers
      if clear_handlers:
          for handler in logging.root.handlers[:]:
              logging.root.removeHandler(handler)
      # Now, add our handlers.
      logging.basicConfig(level=logging_level, handlers=handlers)
  
      registry.register("writer", logger)
  
      return logger
  
imports: import collections
  import collections.abc
  import functools
  import json
  import logging
  import os
  import sys
  import time
  from functools import wraps
  from typing import Any, Callable, Dict, Optional, Union
  import torch
  from mmf.common.registry import registry
  from mmf.utils.configuration import get_mmf_env
  from mmf.utils.distributed import get_rank, is_main, is_xla
  from mmf.utils.file_io import PathManager
  from mmf.utils.timer import Timer
  from termcolor import colored
label_desc: Use image node_id 2 for calling a global function with example usage: setup_logger(output, color, name, disable, clear_handlers) and returns: logger, None