Medius - Rust LibraryLogs & Counters

Diagnostics

Read-only views of the link

logs and counters are lock-free, read-only views on Device and AsyncDevice.

See also: testing with MockBox.

logs

Stream of box messages
fn logs(&self) -> LogStream

No round-trip

Yields each box LOG frame as a LogLine.

EXAMPLE
for line in device.logs() {
    println!("[{:?}] {}", line.level, line.text);
}
// the loop ends here when the link drops

The box emits LOG frames only while the control link is up; with no control PC attached they are dropped, not buffered.

Reading the stream

Blocking, polling, and draining
METHODS
MethodReturnsBlocksDescription
recv()Result<LogLine>YesWaits for the next line. Err is Error::Disconnected once the link is gone.
try_recv()Option<LogLine>NoOne queued line, or None if nothing is waiting.
recv_timeout(d)Option<LogLine>Up to dThe next line within the window, or None on timeout.
try_iter()impl IteratorNoDrains every line queued right now, then stops.
recv_async().awaitResult<LogLine>AwaitsAwait the next line (async feature), runtime-agnostic.
for line in streamLogLineYesBlocking IntoIterator; yields each line until the link closes.

try_iter() or try_recv() for a per-frame loop; recv() or the blocking iterator for a dedicated log thread.

EXAMPLE
let stream = device.logs();

// once per frame: drain whatever is queued, never blocking
for line in stream.try_iter() {
    println!("[{:?}] {}", line.level, line.text);
}

// or wait a bounded window for the next line
if let Some(line) = stream.recv_timeout(Duration::from_millis(50)) {
    println!("got {}", line.text);
} else {
    // no log this window, carry on
}

The channel buffers 1024 lines and evicts the oldest when full. A slow poller drops old lines silently, so drain often if you can't miss any.

counters

Link statistics
fn counters(&self) -> CountersSnapshot

No round-trip

A Copy snapshot of four totals that only climb, reset only on process restart: rising crc_drops means a flaky cable, reconnects counts port reopens after a dropped link. Full field reference on CountersSnapshot.

EXAMPLE
println!("{:?}", device.counters());