code: def log_metric(self, name, value, unit=None, global_step=None, extras=None):
      
      if not isinstance(value, numbers.Number):
        tf.logging.warning(
            "Metric value to log should be a number. Got %s", type(value))
        return
      if extras:
        extras = [{"name": k, "value": v} for k, v in sorted(extras.items())]
      else:
        extras = []
      with tf.gfile.GFile(
          os.path.join(self._logging_dir, METRIC_LOG_FILE_NAME), "a") as f:
        metric = {
            "name": name,
            "value": float(value),
            "unit": unit,
            "global_step": global_step,
            "timestamp": datetime.datetime.now().strftime(
                _DATE_TIME_FORMAT_PATTERN),
            "extras": extras}
        try:
          json.dump(metric, f)
          f.write("\n")
        except (TypeError, ValueError) as e:
          tf.logging.warning("Failed to dump metric to log file: "
                             "name %s, value %s, error %s", name, value, e)
docs: Log the benchmark metric information to local file.
  
      Currently the logging is done in a synchronized way. This should be updated
      to log asynchronously.
  
      Args:
        name: string, the name of the metric to log.
        value: number, the value of the metric. The value will not be logged if it
          is not a number type.
        unit: string, the unit of the metric, E.g "image per second".
        global_step: int, the global_step when the metric is logged.
        extras: map of string:string, the extra information about the metric.