Expand description
Client-side log collection: a tracing-subscriber layer that buffers
structured log records for shipment to iroh-services, plus a reload handle
that lets the cloud control the level filter at runtime.
§The cloud is the source of truth
The level filter starts at off. No tracing events are captured until the
cloud pushes a crate::protocol::SetLogLevel over the ClientHost
channel. The cloud sends one immediately after authenticating a connected
endpoint, derived from the per-endpoint
endpoint_log_settings row (when present) plus the project default.
Concretely this means the install argument is empty: the client process does not get to choose its own log level. The level you see is whatever the dashboard or REST API has decided.
§Typical usage
use iroh_services::logs;
// Buffer-only subscriber, filter starts at `off`.
let collector = logs::install()?;
// Compose with a stderr fmt layer via `logs::layer()` to also render
// filtered events locally:
//
// use tracing_subscriber::prelude::*;
// let (collector, log_layer) = iroh_services::logs::layer();
// tracing_subscriber::registry()
// .with(log_layer)
// .with(tracing_subscriber::fmt::layer())
// .init();
// Hand the collector to the client builder so it pushes batches over RPC,
// and to the ClientHost so the cloud can override the level dynamically.Backed by a bounded VecDeque of LogLine; the oldest entries are dropped
when the buffer fills, with the drop count reported on the next batch.
Structs§
- LogCollector
- Handle to the buffered log collector. Cheap to clone; all clones share the same backing buffer and reload handle.
Enums§
- Install
Error - Errors that can occur while installing the log collector.
- SetFilter
Error - Errors that can occur while changing the active filter at runtime.
Constants§
- DEFAULT_
BUFFER_ CAPACITY - Maximum number of buffered log lines awaiting cloud shipment.
- DEFAULT_
RATE_ PER_ SECOND - Maximum log emission rate per second per process.
Functions§
- install
- Installs a global tracing subscriber whose only output is a JSON-buffering
layer that ships records to the cloud. The level filter starts at
off; the cloud must push aSetLogLevelfor any events to be captured. - layer
- Builds the buffer layer and its
LogCollectorhandle without installing a global subscriber. Use this when composing the collector with other layers; it returns the layer pre-wrapped in the reloadable filter.