class_docstr: Serve Logging Json Formatter
  
  The formatter will generate the json log format on the fly
  based on the field of record.
class_docstr_tok: ["Serve","Logging","Json","Formatter","The","formatter","will","generate","the","json","log","format","on","the","fly","based","on","the","field","of","record","."]
docstr: Format the log record into json format.
  
  Args:
      record: The log record to be formatted.
  
      Returns:
          The formatted log record in json format.
docstr_tok: ["Format","the","log","record","into","json","format",".","Args",":","record",":","The","log","record","to","be","formatted",".","Returns",":","The","formatted","log","record","in","json","format","."]
code: def format(self, record: logging.LogRecord) -> str:
      """Format the log record into json format.
  
      Args:
          record: The log record to be formatted.
  
          Returns:
              The formatted log record in json format.
      """
      record_format = copy.deepcopy(self.component_log_fmt)
      if SERVE_LOG_REQUEST_ID in record.__dict__:
          record_format[SERVE_LOG_REQUEST_ID] = SERVE_LOG_RECORD_FORMAT[
              SERVE_LOG_REQUEST_ID
          ]
      if SERVE_LOG_ROUTE in record.__dict__:
          record_format[SERVE_LOG_ROUTE] = SERVE_LOG_RECORD_FORMAT[
              SERVE_LOG_ROUTE
          ]
  
      if SERVE_LOG_APPLICATION in record.__dict__:
          record_format[
              SERVE_LOG_APPLICATION
          ] = SERVE_LOG_RECORD_FORMAT[SERVE_LOG_APPLICATION]
  
      if SERVE_LOG_MESSAGE in record.__dict__:
          record_format[SERVE_LOG_MESSAGE] = (
              SERVE_LOG_RECORD_FORMAT[SERVE_LOG_MESSAGE]
              % record.__dict__
          )
  
      if SERVE_LOG_EXTRA_FIELDS in record.__dict__:
          if not isinstance(
              record.__dict__[SERVE_LOG_EXTRA_FIELDS], dict
          ):
              raise ValueError(
                  f"Expected a dictionary passing into {SERVE_LOG_EXTRA_FIELDS}, "
                  f"but got {type(record.__dict__[SERVE_LOG_EXTRA_FIELDS])}"
              )
          for k, v in record.__dict__[SERVE_LOG_EXTRA_FIELDS].items():
              if k in record_format:
                  raise KeyError(
                      f"Found duplicated key in the log record: {k}"
                  )
              record_format[k] = v
  
      # create a formatter using the format string
      formatter = logging.Formatter(json.dumps(record_format))
  
      # format the log record using the formatter
      return formatter.format(record)
  
imports: import copy
  import json
  import logging
  import os
  from typing import Optional, Tuple
  import ray
  from ray.serve._private.common import ServeComponentType
  from ray.serve._private.constants import RAY_SERVE_ENABLE_CPU_PROFILING, RAY_SERVE_ENABLE_JSON_LOGGING, RAY_SERVE_ENABLE_MEMORY_PROFILING, SERVE_LOG_APPLICATION, SERVE_LOG_COMPONENT, SERVE_LOG_COMPONENT_ID, SERVE_LOG_DEPLOYMENT, SERVE_LOG_EXTRA_FIELDS, SERVE_LOG_LEVEL_NAME, SERVE_LOG_MESSAGE, SERVE_LOG_RECORD_FORMAT, SERVE_LOG_REPLICA, SERVE_LOG_REQUEST_ID, SERVE_LOG_ROUTE, SERVE_LOG_TIME, SERVE_LOGGER_NAME
  from ray.serve.schema import EncodingType, LoggingConfig
label_desc: Use image node_id 2 for calling the ServeJSONFormatter obj's underlying member method code with example usage: obj.format(record) and returns: formatter