code: def _log(
      msg_type: str,
      log_type: str,
      is_response: bool = False,
      record: Optional["pb.Record"] = None,
      result: Optional["pb.Result"] = None,
      resource: Optional[str] = None,
  ) -> None:
      prefix = "TRACELOG(1)"
      tname = threading.current_thread().name
      now = datetime.datetime.now()
      ts = now.strftime("%H%M%S.%f")
      arrow = "<-" if is_response else "->"
      resource = resource or "unknown"
      uuid = ""
      data = record or result
      record_id = ""
      if data:
          uuid = data.uuid or uuid
          record_id = data._info._tracelog_id
      uuid = uuid or "-"
      record_id = record_id or "-"
      relay = ""
      if data and data.control and data.control.relay_id:
          relay = data.control.relay_id
      relay = relay or "-"
      line = f"{prefix} {arrow} {ts} {record_id:16} {log_type:7} {resource:8} {tname:16} {msg_type:32} {uuid:32} {relay:32}"
      if tracelog_mode == "stdout":
          stdout_write(f"{line}\n")
      elif tracelog_mode == "stderr":
          stderr_write(f"{line}\n")
      elif tracelog_mode == "logger":
          logger.info(line)
  
imports: import datetime
  import logging
  import secrets
  import sys
  import threading
  from typing import TYPE_CHECKING, Optional, cast
label_desc: Use image node_id 1 for calling a global function with example usage: _log(msg_type, log_type, is_response, record, result, resource) without return types