Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Tracing demo

  • trace
  • tracing
  • tracing-subscriber
[package]
name = "demo"
version = "0.1.0"
edition = "2024"

[dependencies]
tracing = "0.1"
tracing-subscriber = "0.3.0"
use tracing::{Level, debug, info};
use tracing_subscriber::FmtSubscriber;

fn main() {
    // Set up a tracing subscriber that logs to stdout.
    let subscriber = FmtSubscriber::builder()
        .with_max_level(Level::TRACE)
        .finish();
    tracing::subscriber::set_global_default(subscriber).expect("setting default subscriber failed");

    // Emit some log messages.
    info!("hello world");

    let number_of_yaks = 3;
    debug!(number_of_yaks, "preparing to shave yaks");
}