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
.
§Panics
- If the subscriber’s background thread could not be spawned.
- If the default
tracing
subscriber has already been set.
§Configuration
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 Variable | Purpose | Default Value |
---|---|---|
TOKIO_CONSOLE_RETENTION | The number of seconds to accumulate completed tracing data | 3600s (1h) |
TOKIO_CONSOLE_BIND | A HOST:PORT description, such as localhost:1234 | 127.0.0.1:6669 |
TOKIO_CONSOLE_PUBLISH_INTERVAL | The number of milliseconds to wait between sending updates to the console | 1000ms (1s) |
TOKIO_CONSOLE_RECORD_PATH | The file path to save a recording | None |
RUST_LOG | Configures 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 as
Targets`, 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();
tracing_subscriber::registry()
.with(console_layer)
.with(tracing_subscriber::fmt::layer())
// .with(..potential additional layer..)
.init();
Calling console_subscriber::init
is equivalent to the following:
use console_subscriber::ConsoleLayer;
ConsoleLayer::builder().with_default_env().init();