Function console_subscriber::init

source ·
pub fn init()
Expand description

Initializes the console tracing Subscriber and starts the console subscriber Server on its own background thread.

This function represents the easiest way to get started using tokio-console.

In addition to the ConsoleLayer, which collects instrumentation data consumed by the console, the default Subscriber initialized by this function also includes a tracing_subscriber::fmt layer, which logs tracing spans and events to stdout. Which spans and events are logged will be determined by the RUST_LOG environment variable.

Note: this function sets the default tracing subscriber for your application. If you need to add additional layers to a subscriber, see spawn.



Tokio console subscriber is configured with sensible defaults for most use cases. If you need to tune these parameters, several environmental configuration variables are available:

Environment VariablePurposeDefault Value
TOKIO_CONSOLE_RETENTIONThe number of seconds to accumulate completed tracing data3600s (1h)
TOKIO_CONSOLE_BINDA HOST:PORT description, such as localhost:1234127.0.0.1:6669
TOKIO_CONSOLE_PUBLISH_INTERVALThe number of milliseconds to wait between sending updates to the console1000ms (1s)
TOKIO_CONSOLE_RECORD_PATHThe file path to save a recordingNone
RUST_LOGConfigures what events are logged events. See Targets for details.“error”

If the “env-filter” crate feature flag is enabled, the RUST_LOG environment variable will be parsed using the EnvFilter type from tracing-subscriber. If the "env-filter" feature is **not** enabled, the [Targets] filter is used instead. The EnvFiltertype accepts all the same syntax asTargets`, but with the added ability to filter dynamically on span field values. See the documentation for those types for details.

Further customization

To add additional layers or replace the format layer, replace console_subscriber::init with:

use tracing_subscriber::prelude::*;

let console_layer = console_subscriber::spawn();

//  .with(..potential additional layer..)

Calling console_subscriber::init is equivalent to the following:

use console_subscriber::ConsoleLayer;