Skip to content

Logging — API reference

log_file_path

log_file_path() -> Path

Return the active log file path, creating its directory if needed.

The log-file setting when set to a concrete path, otherwise <state-dir>/mait-code.jsonl. The one resolution shared by the writing side (:func:setup_logging) and the read side (the mait-code logs viewer).

log_invocation

log_invocation(
    *,
    name: str | None = None,
    truncate_params: set[str] | None = None,
) -> Callable[[Callable[..., Any]], Callable[..., Any]]

Decorate CLI tool/hook entry points so invocations are logged.

Logs the command name and parsed arguments on entry (event: invoked, args), and status plus duration on exit (event: completed / failed / exited, duration_ms).

PARAMETER DESCRIPTION
name

Override the logged command name (default: the wrapped function's name).

TYPE: str | None DEFAULT: None

truncate_params

Extra parameter names to truncate beyond the built-in sensitive set.

TYPE: set[str] | None DEFAULT: None

RETURNS DESCRIPTION
Callable[[Callable[..., Any]], Callable[..., Any]]

A decorator that wraps the entry-point function.

setup_logging

setup_logging() -> None

Configure the mait_code logger hierarchy with a daily-rotating file handler.

Safe to call multiple times — subsequent calls are no-ops.

Also injects the settings [env] table into the process environment (:func:mait_code.config.apply_env): every tool and hook entry point passes through here, making it the shared startup path.