pub struct EventEmitter { /* private fields */ }Expand description
Appends structured events to a JSONL file. Cheap to clone (just a path); the
emitter holds no long-lived file descriptor, so rotation cannot strand a
stale fd (Concurrency invariant: “open with O_APPEND per emission”).
Implementations§
Source§impl EventEmitter
impl EventEmitter
Sourcepub fn new(path: impl Into<PathBuf>, source: impl Into<String>) -> Self
pub fn new(path: impl Into<PathBuf>, source: impl Into<String>) -> Self
Construct an emitter writing to path, tagging every line with
source (e.g. "daemon", "worker:wkA") so consumers can filter by
emitter when cross-emitter ordering matters.
Sourcepub fn emit<P: Serialize>(
&self,
kind: &str,
payload: &P,
) -> Result<(), EmitError>
pub fn emit<P: Serialize>( &self, kind: &str, payload: &P, ) -> Result<(), EmitError>
Emit kind with a structured payload. The payload must serialize to a
JSON object; the emitter frames it as {ts, type: kind, source, data}
(wall-clock RFC3339 ts), so payload keys live under data and never
collide with the envelope fields.
Returns Ok(()) on a successful append. An oversized payload is NOT an
error to the caller: the meta-event is written and Ok(()) returned, so
callers cannot accidentally treat “too large” as “not emitted”.
Trait Implementations§
Source§impl Clone for EventEmitter
impl Clone for EventEmitter
Source§fn clone(&self) -> EventEmitter
fn clone(&self) -> EventEmitter
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more