code: def log(message, print_string=True):
      """
      Prints a message to stdout and writes it to the logfile (requires user to
      call init_logging() at least once in order to save to file).
      :param message: the string to log;
      :param print_string: whether to print the string to stdout;
      """
      global LOGFILE
      message = (
          pformat(message)
          if isinstance(message, dict)
          else str(message)
      )
      if print_string:
          print(message)
      if not message.endswith("\n"):
          message += "\n"
      if LOGFILE:
          with open(LOGFILE, "a") as f:
              f.write(message)
  
imports: import os
  import time
  from pprint import pformat
label_desc: Use image node_id 2 for calling a global function with example usage: log(message, print_string) without return types