Skip to main content

Module log_buffer

Module log_buffer 

Source
Expand description

Bounded in-memory ring buffer of recent tracing log lines.

Why: trusty-* daemons expose a /logs/tail endpoint so operators can read recent logs over HTTP without file I/O or a daemon restart. The buffer and its tracing_subscriber::Layer live here so every daemon shares one impl. What: LogBuffer (thread-safe capped VecDeque<String>) plus LogBufferLayer (the tracing layer that feeds it). Test: cargo test -p trusty-common log_buffer covers capacity eviction, tail semantics, and layer capture. Bounded in-memory ring buffer of recent tracing log lines.

Why: Operators debugging a running daemon want the last N log lines without SSHing to the box, tailing a file, or restarting with a different RUST_LOG. A small in-process ring buffer lets the daemon serve recent logs over HTTP (GET /logs/tail) at near-zero cost and with no file I/O. The cap keeps memory bounded on a long-running process. What: [LogBuffer] is a thread-safe VecDeque<String> capped at a fixed capacity; the oldest line is evicted on overflow. [LogBufferLayer] is a tracing_subscriber::Layer that formats every event into one line and pushes it onto the buffer. The HTTP handler drains the tail. Test: see the tests module — capacity eviction, tail semantics, and a layer-integration test that emits events through a real subscriber.

Structs§

LogBuffer
Thread-safe, bounded ring buffer of formatted log lines.
LogBufferLayer
tracing_subscriber::Layer that mirrors every event into a LogBuffer.

Constants§

DEFAULT_LOG_CAPACITY
Default ring-buffer capacity (lines). Sized so a daemon retains a few minutes of INFO-level chatter while costing well under 1 MB of RAM.