Logs & counters
logs and counters are lock-free, on both Device and AsyncDevice.
See also: testing with MockBox.
logsStream 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);
}
// ends when the link drops or the stream closesThe box sends LOG frames only while the control link is up. With no control PC, they are dropped, not buffered.
Reading the stream Blocking, polling, and draining
METHODS
| Name | Returns | Blocks | Description |
|---|---|---|---|
recv() | Result<LogLine> | Yes | Waits for the next line. Err is Error::Disconnected once the link is gone or the stream is closed. |
try_recv() | Option<LogLine> | No | One queued line, or None. |
recv_timeout(d) | Option<LogLine> | Up to d | The next line within the window, or None on timeout. |
try_iter() | impl Iterator | No | Drains every queued line, then stops. |
recv_async().await | Result<LogLine> | Awaits | Awaits the next line (async feature), runtime-agnostic. |
for line in stream | LogLine | Yes | Blocking IntoIterator; yields each line until the link or the stream closes. |
is_connected() | bool | No | Whether the box still delivers to this stream. A None from try_recv or recv_timeout can't tell you this. |
close() | () | No | Ends this stream and its clones. A blocked receive returns at once, and so does every later one. Other LogStreams keep reading. |
closer() | StreamCloser | No | A handle that closes the stream from another thread. |
Use try_iter() or try_recv() in a per-frame loop, and recv() or the blocking iterator on a dedicated log thread.
EXAMPLE
let stream = device.logs();
// once per frame: drain the queue, never blocking
for line in stream.try_iter() {
println!("[{:?}] {}", line.level, line.text);
}
// or wait up to 50 ms for the next line
if let Some(line) = stream.recv_timeout(Duration::from_millis(50)) {
println!("got {}", line.text);
} else {
// none this window
}The channel buffers 1024 lines. When full, it evicts the oldest line, uncounted.
countersLink statistics
fn counters(&self) -> CountersSnapshot
No round-trip
A Copy snapshot of five totals that only climb, zeroed at process start. Rising crc_drops means a flaky cable. reconnects counts port reopens after a dropped link. restarts counts device-chip restarts the library recovered from. Fields are on CountersSnapshot.
EXAMPLE
let c = device.counters();
println!("{} reconnects, {} restarts, {} CRC drops", c.reconnects, c.restarts, c.crc_drops);