code: def contextual_log_handler(context, path, log_obj=None, level=logging.DEBUG,
                             formatter=None):
      
      log_obj = log_obj or log
      formatter = formatter or logging.Formatter(
          fmt=context.config['log_fmt'],
          datefmt=context.config['log_datefmt'],
      )
      parent_path = os.path.dirname(path)
      makedirs(parent_path)
      contextual_handler = logging.FileHandler(path, encoding='utf-8')
      contextual_handler.setLevel(level)
      contextual_handler.setFormatter(formatter)
      log_obj.addHandler(contextual_handler)
      yield
      contextual_handler.close()
      log_obj.removeHandler(contextual_handler)
docs: Add a short-lived log with a contextmanager for cleanup.
  
      Args:
          context (scriptworker.context.Context): the scriptworker context
          path (str): the path to the log file to create
          log_obj (logging.Logger): the log object to modify.  If None, use
              ``scriptworker.log.log``.  Defaults to None.
          level (int, optional): the logging level.  Defaults to logging.DEBUG.
          formatter (logging.Formatter, optional): the logging formatter. If None,
              defaults to ``logging.Formatter(fmt=fmt)``. Default is None.
  
      Yields:
          None: but cleans up the handler afterwards.