vibeqc.StructuredLog¶
- class vibeqc.StructuredLog(path=None, *, enabled=True)[source]¶
Bases:
objectOne-record-per-line NDJSON writer with line-flushed I/O.
Construct via
structured_log()(the context manager) for the common case. Direct construction is supported for tests / advanced callers that want to manage the lifetime themselves — callclose()when done.- Parameters:
path (Union[str, os.PathLike, None]) – Destination NDJSON file. Truncated on construction so a fresh run doesn’t accumulate alongside last week’s tail. The parent directory is created if missing.
enabled (bool) – If
False, allemit()calls are no-ops and the file is not opened. Lets callers pass through aStructuredLogunconditionally without wrapping everyemitin anif log:guard.
Notes
Each
emit()call:stamps
timestamp(ISO-8601 with timezone) onto the record,encodes via
json.dumps()withallow_nan=False(jq- compatible),writes a single line +
\n, thenflush()so atail -fsees records as they land.
A logging failure (disk full, permissions, …) is caught and a one-line warning emitted to stderr; the calculation continues. This matches
vibeqc.ProgressLoggerandvibeqc.PerfTracker.Methods
__init__([path, enabled])close()Flush + close the underlying file handle.
emit(event, **payload)Write one record with
"event": eventpluspayload.Attributes
- emit(event, **payload)[source]¶
Write one record with
"event": eventpluspayload.payloadkeys overwrite"event"if a caller passesevent=...as a kwarg — last-write-wins, matchingdictconstruction.