pub struct EventLog { /* private fields */ }Expand description
Thread-safe ring-buffer event log. Automatically evicts the oldest events when capacity is reached. All operations recover from mutex poisoning.
Implementations§
Source§impl EventLog
impl EventLog
Sourcepub fn new(max_capacity: usize) -> Self
pub fn new(max_capacity: usize) -> Self
Creates a new event log with the given maximum capacity.
use victauri_core::EventLog;
let log = EventLog::new(100);
assert!(log.is_empty());
assert_eq!(log.capacity(), 100);Sourcepub fn push(&self, event: AppEvent)
pub fn push(&self, event: AppEvent)
Appends an event, evicting the oldest if at capacity.
§Examples
use victauri_core::{EventLog, AppEvent};
use chrono::Utc;
let log = EventLog::new(100);
log.push(AppEvent::state_change("theme", Utc::now(), None));
assert_eq!(log.len(), 1);
assert_eq!(log.snapshot().len(), 1);Sourcepub fn snapshot_range(&self, offset: usize, limit: usize) -> Vec<AppEvent>
pub fn snapshot_range(&self, offset: usize, limit: usize) -> Vec<AppEvent>
Returns a paginated slice of events starting at offset, up to limit items.
Sourcepub fn since(&self, timestamp: DateTime<Utc>) -> Vec<AppEvent>
pub fn since(&self, timestamp: DateTime<Utc>) -> Vec<AppEvent>
Returns all events with a timestamp at or after the given time.
Sourcepub fn ipc_calls(&self) -> Vec<IpcCall>
pub fn ipc_calls(&self) -> Vec<IpcCall>
Returns all IPC call events, filtering out non-IPC events.
§Examples
use victauri_core::{EventLog, AppEvent, IpcCall, IpcResult};
use chrono::Utc;
let log = EventLog::new(100);
log.push(AppEvent::Ipc(IpcCall::new(
"c1",
"greet",
Utc::now(),
IpcResult::Ok(serde_json::json!("hi")),
Some(5),
0,
"main",
)));
assert_eq!(log.ipc_calls().len(), 1);Sourcepub fn recent_ipc_calls(&self, limit: usize) -> Vec<IpcCall>
pub fn recent_ipc_calls(&self, limit: usize) -> Vec<IpcCall>
Returns the newest limit IPC calls, oldest first.
Unlike ipc_calls this clones only the calls it returns (a call
carries its whole request/response body), so its cost is bounded by limit, not by the
size of the log.
Sourcepub fn ipc_command_names(&self) -> BTreeSet<String>
pub fn ipc_command_names(&self) -> BTreeSet<String>
Returns the distinct command names of the IPC calls in the log, without cloning the calls themselves.