code: def log_to_file(file_out, protocol="json"):
      """Log the tuning records into file.
      The rows of the log are stored in the format of autotvm.record.encode.
  
      Parameters
      ----------
      file_out : File or str
          The file to log to.
      protocol: str, optional
          The log protocol. Can be 'json' or 'pickle'
  
      Returns
      -------
      callback : callable
          Callback function to do the logging.
      """
  
      def _callback(_, inputs, results):
          """Callback implementation"""
          if isinstance(file_out, str):
              with open(file_out, "a") as f:
                  for inp, result in zip(inputs, results):
                      f.write(
                          record.encode(inp, result, protocol) + "\n"
                      )
          else:
              for inp, result in zip(inputs, results):
                  file_out.write(
                      record.encode(inp, result, protocol) + "\n"
                  )
  
      # pylint: disable=import-outside-toplevel
      from pathlib import Path
  
      if isinstance(file_out, Path):
          file_out = str(file_out)
  
      return _callback
  
file_path: tvm/python/tvm/autotvm/tuner/callback.py
imports: import sys
  import time
  import logging
  import numpy
  from ..None import record
  from ..utils import format_si_prefix
label_desc: Use image node_id 1 for calling a global function with example usage: log_to_file(file_out, protocol) and returns: _callback