🛈 Note: This is pre-release documentation for the upcoming tracing 0.2.0 ecosystem.

For the release documentation, please see docs.rs, instead.

Function tracing_subscriber::fmt::fmt

source ·
pub fn fmt() -> CollectorBuilder
Available on crate features fmt and std only.
Expand description

Returns a new CollectorBuilder for configuring a formatting collector.

This is essentially shorthand for CollectorBuilder::default().


Using init to set the default collector:


Configuring the output format:

    // Configure formatting settings.
    // Set the collector as the default.

try_init returns an error if the default collector could not be set:

use std::error::Error;

fn init_subscriber() -> Result<(), Box<dyn Error + Send + Sync + 'static>> {
        // Configure the collector to emit logs in JSON format.
        // Configure the collector to flatten event fields in the output JSON objects.
        // Set the collector as the default, returning an error if this fails.


Rather than setting the collector as the default, finish returns the constructed collector, which may then be passed to other functions:

let collector = tracing_subscriber::fmt()

tracing::collect::with_default(collector, || {
    // the collector will only be set as the default
    // inside this closure...