Skip to main content

init_tracing_with_buffer

Function init_tracing_with_buffer 

Source
pub fn init_tracing_with_buffer(verbose_count: u8, capacity: usize) -> LogBuffer
Expand description

Initialise the global tracing subscriber and capture events into a log_buffer::LogBuffer so the daemon can serve recent logs over HTTP.

Why: daemons expose GET /logs/tail, which needs an in-memory ring of recent log lines. Routing capture through the subscriber means every existing tracing::info! / warn! call site is mirrored automatically — no second logging API to keep in sync. The stderr fmt layer is retained so operators still see live logs in the terminal / launchd log file. What: builds a tracing_subscriber::registry with two layers — the standard stderr fmt layer (same verbosity ladder + RUST_LOG override as init_tracing) and a log_buffer::LogBufferLayer feeding the returned log_buffer::LogBuffer. Uses try_init, so a process that has already installed a subscriber keeps it; the returned buffer is still valid (just empty) in that case. Test: cargo test -p trusty-common log_buffer covers the layer; the daemon /logs/tail integration tests cover the wired path end-to-end.