pub struct EventLog { /* private fields */ }Expand description
An append-only event log backed by a JSONL file.
Implementations§
Source§impl EventLog
impl EventLog
Sourcepub fn open(session_dir: &Path) -> Result<Self, EventLogError>
pub fn open(session_dir: &Path) -> Result<Self, EventLogError>
Open or create an event log for the given session directory.
The session directory is typically .treeship/sessions/<session_id>/.
If the directory does not exist, it will be created.
Initialization reads the counter sidecar in O(1) when present and consistent with events.jsonl’s byte size; falls back to an O(N) line count (and rewrites the sidecar) when the sidecar is missing, short-read, or stale from a crashed previous appender.
Sourcepub fn append(&self, event: &mut SessionEvent) -> Result<(), EventLogError>
pub fn append(&self, event: &mut SessionEvent) -> Result<(), EventLogError>
Append a single event to the log.
The event’s sequence_no is set automatically. Under contention from
multiple writer processes, the sequence number is re-derived from the
on-disk line count under an exclusive flock so two parallel writers
never collide.
Sourcepub fn read_all(&self) -> Result<Vec<SessionEvent>, EventLogError>
pub fn read_all(&self) -> Result<Vec<SessionEvent>, EventLogError>
Read all events from the log.
Sourcepub fn event_count(&self) -> u64
pub fn event_count(&self) -> u64
Return the current event count.