Function console_subscriber::spawn

source ·
pub fn spawn<S>() -> impl Layer<S>
where S: Subscriber + for<'a> LookupSpan<'a>,
Expand description

Returns a new tracing_subscriber Layer configured with a ConsoleLayer and a filter that enables the spans and events required by the console.

This function spawns the console subscriber’s Server in its own Tokio runtime in a background thread.

Unlike init, this function does not set the default subscriber, allowing additional Layers to be added.

This function is equivalent to the following:

use console_subscriber::ConsoleLayer;

let layer = ConsoleLayer::builder().with_default_env().spawn();

§Panics

  • If the subscriber’s background thread could not be spawned.

§Configuration

console_subscriber::build supports all of the environmental configuration described at console_subscriber::init.

§Differences from init

Unlike console_subscriber::init, this function does not add a tracing_subscriber::fmt layer to the configured Layer. This means that this function will not log spans and events based on the value of the RUST_LOG environment variable. Instead, a user-provided fmt::Layer can be added in order to customize the log format.

You must call .init() on the final subscriber in order to set the subscriber as the default.

§Examples

use tracing_subscriber::prelude::*;
tracing_subscriber::registry()
    .with(console_subscriber::spawn())
    .with(tracing_subscriber::fmt::layer())
//  .with(...)
    .init();