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

Simple tracing configuration with RUST_LOG environment variable

[package]
name = "demo-rust-log-env"
version = "0.1.0"
edition = "2024"

[dependencies]
tracing = "0.1"
tracing-subscriber = "0.3.0"
use tracing::{debug, error, info, trace, warn};

fn main() {
    // Set up a tracing subscriber that logs to stdout.
    // User RUST_LOG to control the logging level.
    // RUST_LOG=trace
    // RUST_LOG=error
    tracing_subscriber::fmt::init();

    // Emit some log messages.
    trace!("trace");
    debug!("debug");
    info!("info");
    warn!("warn");
    error!("error");
}