You can integrate console-subscriber into your application using several methods depending on your needs for configuration and layer composition.
Simple Initialization
For a quick setup that sets the default tracing subscriber and serves telemetry (while also logging to stdout via RUST_LOG), call init() in your main function.
Programmatic Configuration with Builder
Use the ConsoleLayer::builder() to customize settings such as data retention duration and the gRPC server address.
Combining with other Tracing Layers
If you are using a tracing-subscriber::Registry, you can use console_subscriber::spawn() to create a Layer that runs the console server in the background, allowing you to compose it with other layers like fmt::layer().
// Simple initialization
console_subscriber::init();
// Programmatic configuration
use std::time::Duration;
console_subscriber::ConsoleLayer::builder()
.retention(Duration::from_secs(60))
.server_addr(([127, 0, 0, 1], 5555))
.init();
// Combining with other layers
use tracing_subscriber::prelude::*;
let console_layer = console_subscriber::spawn();
tracing_subscriber::registry()
.with(console_layer)
.with(tracing_subscriber::fmt::layer())
.init();