Skip to content

logs

logs

Log service - handles log file reading and streaming.

Supports: - Reading log files - Tailing log files (last N lines) - Streaming logs via Server-Sent Events (SSE)

LogService(status_dir: Path)

Service for reading and streaming job logs.

read_log(project: str, group: str, name: str, run_id: str, offset: int = 0, limit: Optional[int] = None) -> tuple[str, int]

Read log file contents.

Parameters:

Name Type Description Default
project str

Project name

required
group str

Group name

required
name str

Job name

required
run_id str

Run ID

required
offset int

Byte offset to start reading from

0
limit Optional[int]

Maximum bytes to read (None for all)

None

Returns:

Type Description
tuple[str, int]

Tuple of (content, new_offset)

tail_log(project: str, group: str, name: str, run_id: str, lines: int | None = None) -> str

Read the last N lines of a log file, or entire file if lines=None.

Parameters:

Name Type Description Default
lines int | None

Number of lines to return from end. None = entire file.

None

stream_log(project: str, group: str, name: str, run_id: str, poll_interval: float = 1.0) -> AsyncGenerator[str, None] async

Stream log file contents as they're written.

Yields new content whenever the file is updated. Uses polling - TODO: consider inotify/fsevents for efficiency.

get_log_size(project: str, group: str, name: str, run_id: str) -> int

Get the size of a log file in bytes.

log_exists(project: str, group: str, name: str, run_id: str) -> bool

Check if a log file exists.