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.
The env_logger crate lets your Rust program print log messages like 'info' or 'error' to the console. You control which messages appear by setting a simple environment variable before running the code. Think of it like a volume knob for your program's internal chatter, letting you hear only what matters.