Skip to main content

JsonlReporter

Struct JsonlReporter 

Source
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,

Source

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 - Any Write implementation (file, buffer, stdout, etc.).
Source

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.

Source

pub fn writer(&self) -> &W

Returns a shared reference to the underlying writer.

Useful for inspecting an in-memory buffer after the loop finishes.

Source

pub fn writer_mut(&mut self) -> &mut W

Returns a mutable reference to the underlying writer.

Source

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>
where W: Write + Send,

Source§

fn handle_event(&mut self, event: AgentEvent)

Called synchronously for every AgentEvent emitted by the loop driver.

Auto Trait Implementations§

§

impl<W> Freeze for JsonlReporter<W>
where W: Freeze,

§

impl<W> !RefUnwindSafe for JsonlReporter<W>

§

impl<W> Send for JsonlReporter<W>
where W: Send,

§

impl<W> Sync for JsonlReporter<W>
where W: Sync,

§

impl<W> Unpin for JsonlReporter<W>
where W: Unpin,

§

impl<W> UnsafeUnpin for JsonlReporter<W>
where W: UnsafeUnpin,

§

impl<W> !UnwindSafe for JsonlReporter<W>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.