pub struct JsonlReporter<W> { /* private fields */ }Expand description
Machine-readable reporter that writes one JSON object per line (JSONL).
Each AgentEvent is wrapped in an EventEnvelope with a timestamp
and serialized as a single JSON line. This format is easy to ingest in
log aggregation systems or to replay offline.
I/O and serialization errors are collected internally and can be
retrieved with take_errors.
§Example
use agentkit_reporting::JsonlReporter;
// Write JSONL to an in-memory buffer (useful in tests).
let reporter = JsonlReporter::new(Vec::new());
// Write JSONL to a file, flushing after every event.
let file = std::fs::File::create("events.jsonl")?;
let reporter = JsonlReporter::new(std::io::BufWriter::new(file));Implementations§
Source§impl<W> JsonlReporter<W>where
W: Write,
impl<W> JsonlReporter<W>where
W: Write,
Sourcepub fn new(writer: W) -> Self
pub fn new(writer: W) -> Self
Creates a new JsonlReporter writing to the given writer.
Flushing after each event is enabled by default. Disable it with
with_flush_each_event(false)
if you are writing to a buffered sink and prefer to flush manually.
§Arguments
writer- AnyWriteimplementation (file, buffer, stdout, etc.).
Sourcepub fn with_flush_each_event(self, flush_each_event: bool) -> Self
pub fn with_flush_each_event(self, flush_each_event: bool) -> Self
Controls whether the writer is flushed after every event (builder pattern).
Defaults to true. Set to false when batching writes for throughput.
Sourcepub fn writer(&self) -> &W
pub fn writer(&self) -> &W
Returns a shared reference to the underlying writer.
Useful for inspecting an in-memory buffer after the loop finishes.
Sourcepub fn writer_mut(&mut self) -> &mut W
pub fn writer_mut(&mut self) -> &mut W
Returns a mutable reference to the underlying writer.
Sourcepub fn take_errors(&mut self) -> Vec<ReportError>
pub fn take_errors(&mut self) -> Vec<ReportError>
Drains and returns all errors accumulated during event handling.
Subsequent calls return an empty Vec until new errors occur.
Trait Implementations§
Source§impl<W> LoopObserver for JsonlReporter<W>
impl<W> LoopObserver for JsonlReporter<W>
Source§fn handle_event(&mut self, event: AgentEvent)
fn handle_event(&mut self, event: AgentEvent)
AgentEvent emitted by the loop driver.