code: def _log_message(
      msg: "MessageType", log_type: str, resource: Optional[str] = None
  ) -> None:
      record: Optional[pb.Record] = None
      result: Optional[pb.Result] = None
      is_response = False
      msg_type: str
      # Note: using strings to avoid an import
      message_type_str = type(msg).__name__
      if message_type_str == "Record":
          record = cast("pb.Record", msg)
          msg_type = _record_msg_type(record)
      elif message_type_str == "Result":
          is_response = True
          result = cast("pb.Result", msg)
          msg_type = _result_msg_type(result)
      elif message_type_str == "ServerRequest":
          server_request = cast("spb.ServerRequest", msg)
          msg_type = str(
              server_request.WhichOneof("server_request_type")
          )
          if msg_type == "record_publish":
              record = server_request.record_publish
              sub_msg_type = _record_msg_type(record)
              msg_type = f"pub-{sub_msg_type}"
          elif msg_type == "record_communicate":
              record = server_request.record_communicate
              sub_msg_type = _record_msg_type(record)
              msg_type = f"comm-{sub_msg_type}"
          # print("SRV", server_request)
      elif message_type_str == "ServerResponse":
          is_response = True
          server_response = cast("spb.ServerResponse", msg)
          msg_type = str(
              server_response.WhichOneof("server_response_type")
          )
          if msg_type == "result_communicate":
              result = server_response.result_communicate
              sub_msg_type = _result_msg_type(result)
              msg_type = f"comm-{sub_msg_type}"
      else:
          raise AssertionError(
              f"Unknown message type {message_type_str}"
          )
      _log(
          msg_type,
          is_response=is_response,
          record=record,
          result=result,
          log_type=log_type,
          resource=resource,
      )
  
imports: import datetime
  import logging
  import secrets
  import sys
  import threading
  from typing import TYPE_CHECKING, Optional, cast
label_desc: Use image node_id 4 for calling a global function with example usage: _log_message(msg, log_type, resource) without return types