Skip to content

output_capture

output_capture

Persist build/run output — terok glue over the terok-util capture facility.

The capture mechanism (pty tee, journald/file sinks) lives in terok_util.output_capture; this module adds only the terok-specific bits: the TEROK_KIND/PROJECT/TASK journald fields and the file-fallback path under core_state_dir. The CLI command handlers wrap an operation with tee_output; everything below the seam is shared with the rest of the fleet.

__all__ = ['tee_output'] module-attribute

tee_output(kind, *, project=None, task_id=None)

Capture a build/run operation's output to journald or a log file.

Thin wrapper over terok_util.output_capture.tee_output: labels the stream with terok's journald fields and resolves the file-fallback path lazily under the core state dir.

Parameters:

Name Type Description Default
kind str

Operation label — "build", "run", or "setup".

required
project str | None

Owning project name, when known.

None
task_id str | None

Owning task id, when known.

None
Source code in src/terok/lib/util/output_capture.py
@contextlib.contextmanager
def tee_output(
    kind: str, *, project: str | None = None, task_id: str | None = None
) -> Iterator[None]:
    """Capture a build/run operation's output to journald or a log file.

    Thin wrapper over
    [`terok_util.output_capture.tee_output`][terok_util.output_capture.tee_output]:
    labels the stream with terok's journald fields and resolves the
    file-fallback path lazily under the core state dir.

    Args:
        kind: Operation label — ``"build"``, ``"run"``, or ``"setup"``.
        project: Owning project name, when known.
        task_id: Owning task id, when known.
    """
    fields = {"TEROK_KIND": kind}
    if project:
        fields["TEROK_PROJECT"] = project
    if task_id:
        fields["TEROK_TASK"] = task_id
    with _util_tee_output(
        _IDENTIFIER,
        fields=fields,
        file_path_fn=lambda: _log_file_path(kind, project, task_id),
    ):
        yield