code: def create_logger(
      log: Union[bool, str, logging.Logger] = True
  ) -> Union[logging.Logger, DummyLogger]:
      """Create and return a logger object.
  
      Parameters
      ----------
      log: bool or str or logging.Logger, default = True
          - If False, don't create any logger (return dummy).
          - If True, create a default logger at logs.log.
          - If str, create a default logger at that path.
          - If logging.Logger, returns the object unchanged.
  
      """
      if not log:
          return DummyLogger(name="DummyLogger")
      elif isinstance(log, logging.Logger):
          return log
  
      logger = logging.getLogger("logs")
      level = os.getenv("PYCARET_CUSTOM_LOGGING_LEVEL", "DEBUG")
      logger.setLevel(level)
      # Do not propagate to the root logger in Jupyter
      logger.propagate = False
  
      # create console handler and set level to debug
      if logger.hasHandlers():
          logger.handlers.clear()
  
      path = "logs.log" if isinstance(log, bool) else log
      ch: Optional[
          Union[logging.FileHandler, logging.NullHandler]
      ] = None
      try:
          ch = logging.FileHandler(path)
      except Exception:
          warnings.warn(
              f"Could not attach a FileHandler to the logger at path {path}! "
              "No logs will be saved."
          )
          traceback.print_exc()
          ch = logging.NullHandler()
      ch.setLevel(logging.DEBUG)
  
      # create formatter
      formatter = logging.Formatter(
          "%(asctime)s:%(levelname)s:%(message)s"
      )
  
      # add formatter to ch
      ch.setFormatter(formatter)
  
      # add ch to logger
      logger.addHandler(ch)
  
      return logger
  
imports: import logging
  import os
  import traceback
  import warnings
  from contextlib import redirect_stderr, redirect_stdout
  from typing import Callable, Optional, Union
label_desc: Use image node_id 2 for calling a global function with example usage: create_logger(log) and returns: logger, DummyLogger, log