ray.util.state.get_log#

ray.util.state.get_log(address: str | None = None, node_id: str | None = None, node_ip: str | None = None, filename: str | None = None, actor_id: str | None = None, task_id: str | None = None, pid: int | None = None, follow: bool = False, tail: int = -1, timeout: int = 30, suffix: str = 'out', encoding: str | None = 'utf-8', errors: str | None = 'strict', submission_id: str | None = None, attempt_number: int = 0, _interval: float | None = None) Generator[str, None, None][source]#

Retrieve log file based on file name or some entities ids (pid, actor id, task id).

Examples

import ray
from ray.util.state import get_log

# Node id could be retrieved from list_nodes() or ray.nodes()
node_id = ray.nodes()[0]["NodeID"]
filename = "raylet.out"
for l in get_log(filename=filename, node_id=node_id):
   print(l)
[2023-05-19 12:35:18,347 I 4259 68399276] (raylet) io_service_pool.cc:35: IOServicePool is running with 1 io_service.
[2023-05-19 12:35:18,348 I 4259 68399276] (raylet) store_runner.cc:32: Allowing the Plasma store to use up to 2.14748GB of memory.
[2023-05-19 12:35:18,348 I 4259 68399276] (raylet) store_runner.cc:48: Starting object store with directory /tmp, fallback /tmp/ray, and huge page support disabled
Parameters:
  • address – Ray bootstrap address, could be auto, localhost:6379. If not specified, it will be retrieved from the initialized ray cluster.

  • node_id – Id of the node containing the logs .

  • node_ip – Ip of the node containing the logs. (At least one of the node_id and node_ip have to be supplied when identifying a node).

  • filename – Name of the file (relative to the ray log directory) to be retrieved.

  • actor_id – Id of the actor if getting logs from an actor.

  • task_id – Id of the task if getting logs from a non concurrent actor. For concurrent actor, please query the log with actor_id.

  • pid – PID of the worker if getting logs generated by a worker. When querying with pid, either node_id or node_ip must be supplied.

  • follow – When set to True, logs will be streamed and followed.

  • tail – Number of lines to get from the end of the log file. Set to -1 for getting the entire log.

  • timeout – Max timeout for requests made when getting the logs.

  • suffix – The suffix of the log file if query by id of tasks/workers/actors. Default to “out”.

  • encoding – The encoding used to decode the content of the log file. Default is “utf-8”. Use None to get binary data directly.

  • errors – The error handling scheme to use for decoding errors. Default is “strict”. See https://docs.python.org/3/library/codecs.html#error-handlers

  • submission_id – Job submission ID if getting log from a submission job.

  • attempt_number – The attempt number of the task if getting logs generated by a task.

  • _interval – The interval in secs to print new logs when follow=True.

Returns:

A Generator of log line, None for SendType and ReturnType.

Raises:

ExceptionsRayStateApiException if the CLI failed to query the data.

DeveloperAPI: This API may change across minor Ray releases.