annie.core.logbook¶
Central event log — a dated file plus an in-memory store for the Log tab (infra).
Errors that happen in the background (lazy decode, render workers, the conversion batch, NiceGUI’s own callbacks) used to escape to the terminal and were easy to miss. The log book gives them one home:
every event is appended to an in-memory ring buffer the Log tab reads, and
mirrored to a per-session file named after the session database (e.g.
annie_2026-01-02_09-00-00.logbeside…/sessions/annie_….db) so a session’s log and its review DB are paired; renaming the DB renames the log (seeLogBook.retarget()), keeping their names in lockstep.
The store is event-sourced: each event has a monotonic seq so a per-client
poller can fetch only what is new (for toasts) without re-rendering everything. It
is pure stdlib and thread-safe, so render/convert worker threads can report too.
Attributes¶
The levels an event can carry, most severe first. |
|
Longest message shown in a toast or a Log tab row; the rest goes to the details. |
|
The process-wide event log. |
Classes¶
Functions¶
|
Record an event on the global |
|
Record an error event whose details are |
Module Contents¶
- annie.core.logbook.LEVELS: tuple[str, ...] = ('error', 'warning', 'info')¶
The levels an event can carry, most severe first.
- class annie.core.logbook.LogEvent[source]¶
One recorded event.
- seq¶
Monotonic sequence number (for incremental polling).
- timestamp¶
When it was recorded.
- message¶
Short, one-line summary.
- details¶
Optional long text (e.g. a traceback) for the expandable view.
- property time_text: str¶
The timestamp formatted as
YYYY-MM-DD HH:MM:SS.
- annie.core.logbook.MAX_MESSAGE_CHARS = 200¶
Longest message shown in a toast or a Log tab row; the rest goes to the details.
- class annie.core.logbook.LogBook(capacity: int = 2000)[source]¶
A thread-safe, bounded event store mirrored to a dated log file.
Create an empty store.
- Parameters:
capacity – Maximum number of events kept in memory (oldest dropped).
- attach_file(log_dir: str | pathlib.Path, name: str) pathlib.Path[source]¶
Mirror events to
<log_dir>/<name>.logand return the file path.- Parameters:
log_dir – Directory to write the log file into (created if needed).
name – Base filename (no suffix) — the session database’s stem, so the log and its review DB share a name and can be found together.
- Returns:
The log file path.
- retarget(db_path: str | pathlib.Path) pathlib.Path | None[source]¶
Rename the active log file to match a (renamed) session database.
The log and its review DB are paired session data, so when the DB is renamed the log follows: the current log file’s content moves to
<logs_dir>/<db_stem>.logand the file handler re-points there. If a log by that name already exists (e.g. switching to a previously used DB), events are appended to it rather than clobbering it.- Parameters:
db_path – The new active database path; its stem names the log.
- Returns:
The new log path, or
Noneif no log file is attached yet.
- add(level: str, message: str, details: str = '') LogEvent[source]¶
Record an event (and mirror it to the file, if attached).
A long or multi-line
message(e.g. one that embeds an exception’s text, which for torchcodec runs to 150 lines) is cut to its first line for the toast and the Log tab row; the full text moves to the top ofdetails, so nothing is lost.
- annie.core.logbook.LOG¶
The process-wide event log.