code: def _init_log(name, max_size, backups, foreground):
      if foreground:
          handler = logging.StreamHandler()
      else:
          logfile = var.logfile(name)
          util.ensure_dir(os.path.dirname(logfile))
          handler = logging.handlers.RotatingFileHandler(
              logfile, maxBytes=max_size, backupCount=backups
          )
      handler.setFormatter(
          logging.Formatter(
              "%(asctime)s %(message)s", "%Y-%m-%d %H:%M:%S"
          )
      )
      log = logging.getLogger("guild." + name)
      log.propagate = False
      log.addHandler(handler)
      return log
  
imports: import os
  import logging
  import psutil
  from guild import var
  from guild import util
label_desc: Use image node_id 2 for calling a global function with example usage: _init_log(name, max_size, backups, foreground) and returns: log