How to use env_logger crate in Rust environment logger

Initialize env_logger in Rust by adding the dependency and calling env_logger::init() in main to enable RUST_LOG environment variable control.

Add env_logger to your dependencies and initialize it in main to configure logging via the RUST_LOG environment variable.

use log::*;

fn main() {
    env_logger::init();
    info!("Application started");
}

Add this to your Cargo.toml:

[dependencies]
env_logger = "0.9"
log = "0.4"

Run your program with RUST_LOG=info to see output.