pub struct EventEmitter { /* private fields */ }Expand description
Ships structured events to the logging daemon’s ingest socket.
Construct it with EventEmitter::new (or EventEmitter::with_socket)
inside a running tokio runtime — the background shipper is spawned at
construction. Clone it freely: every clone shares the one shipper channel and
the one stats handle, so a service can hand a clone to each task that needs to
record an event without standing up a second shipper.
Implementations§
Source§impl EventEmitter
impl EventEmitter
Sourcepub fn new(source: impl Into<String>) -> Self
pub fn new(source: impl Into<String>) -> Self
Build an emitter for the default ingest socket, tagging every event with
source (the binary name). Spawns the background shipper on the current
tokio runtime; must be called from within a runtime context.
Sourcepub fn with_socket(source: impl Into<String>, socket: impl AsRef<Path>) -> Self
pub fn with_socket(source: impl Into<String>, socket: impl AsRef<Path>) -> Self
Build an emitter that ships to an explicit socket path (used by tests). Spawns the background shipper on the current tokio runtime.
Sourcepub fn stats(&self) -> Arc<EmitterStats> ⓘ
pub fn stats(&self) -> Arc<EmitterStats> ⓘ
The diagnostic counters for this emitter (enqueued / dropped).
Sourcepub fn emit(&self, kind: impl Into<String>, severity: Level, detail: Fields)
pub fn emit(&self, kind: impl Into<String>, severity: Level, detail: Fields)
Record one event: kind is the dotted classifier, severity the level,
detail the open field map (redacted in place before it leaves the
process). Wait-free: a full channel drops the event and counts it, a
closed channel (shipper gone) is a silent drop. Never blocks the caller,
so an event recorded from a hot loop or a heartbeat tick cannot stall.