code: def start_log_monitor(
      session_dir: str,
      logs_dir: str,
      gcs_address: str,
      fate_share: Optional[bool] = None,
      max_bytes: int = 0,
      backup_count: int = 0,
      redirect_logging: bool = True,
      stdout_file: Optional[IO[AnyStr]] = subprocess.DEVNULL,
      stderr_file: Optional[IO[AnyStr]] = subprocess.DEVNULL,
  ):
      """Start a log monitor process.
  
      Args:
          session_dir: The session directory.
          logs_dir: The directory of logging files.
          gcs_address: GCS address for pubsub.
          fate_share: Whether to share fate between log_monitor
              and this process.
          max_bytes: Log rotation parameter. Corresponding to
              RotatingFileHandler's maxBytes.
          backup_count: Log rotation parameter. Corresponding to
              RotatingFileHandler's backupCount.
          redirect_logging: Whether we should redirect logging to
              the provided log directory.
          stdout_file: A file handle opened for writing to redirect stdout to. If
              no redirection should happen, then this should be None.
          stderr_file: A file handle opened for writing to redirect stderr to. If
              no redirection should happen, then this should be None.
  
      Returns:
          ProcessInfo for the process that was started.
      """
      log_monitor_filepath = os.path.join(
          RAY_PATH, RAY_PRIVATE_DIR, "log_monitor.py"
      )
  
      command = [
          sys.executable,
          "-u",
          log_monitor_filepath,
          f"--session-dir={session_dir}",
          f"--logs-dir={logs_dir}",
          f"--gcs-address={gcs_address}",
          f"--logging-rotate-bytes={max_bytes}",
          f"--logging-rotate-backup-count={backup_count}",
      ]
  
      if not redirect_logging:
          # If not redirecting logging to files, unset log filename.
          # This will cause log records to go to stderr.
          command.append("--logging-filename=")
          # Use stderr log format with the component name as a message prefix.
          logging_format = ray_constants.LOGGER_FORMAT_STDERR.format(
              component=ray_constants.PROCESS_TYPE_LOG_MONITOR
          )
          command.append(f"--logging-format={logging_format}")
          # Inherit stdout/stderr streams.
          stdout_file = None
          stderr_file = None
      process_info = start_ray_process(
          command,
          ray_constants.PROCESS_TYPE_LOG_MONITOR,
          stdout_file=stdout_file,
          stderr_file=stderr_file,
          fate_share=fate_share,
      )
      return process_info
  
imports: import base64
  import collections
  import errno
  import io
  import json
  import logging
  import mmap
  import multiprocessing
  import os
  import random
  import shutil
  import signal
  import socket
  import subprocess
  import sys
  import time
  from pathlib import Path
  from typing import List, Optional, IO, AnyStr
  import psutil
  from filelock import FileLock
  import ray
  import ray._private.ray_constants
  from ray._raylet import GcsClient, GcsClientOptions
  from ray.core.generated.common_pb2 import Language
  from ray._private.ray_constants import RAY_NODE_IP_FILENAME
label_desc: Use image node_id 30 for calling a global function with example usage: start_log_monitor(session_dir, logs_dir, gcs_address, fate_share, max_bytes, backup_count, redirect_logging, stdout_file, stderr_file) and returns: process_info