Add log and env_logger to Cargo.toml, initialize the backend in main, and use log macros to output messages.
Add the log and a backend like env_logger to your Cargo.toml, initialize the logger in main, then use macros like info! to log messages.
[dependencies]
log = "0.4"
env_logger = "0.11"
use log::{info, LevelFilter};
fn main() {
env_logger::Builder::from_env(env_logger::Env::default().default_filter_or("info"))
.format_timestamp(None)
.init();
info!("Application started");
}
The log crate provides a standard way to write messages about what your program is doing without worrying about how they are displayed. You pair it with a specific 'backend' crate that decides where those messages go, like your terminal or a file. Think of log as the universal remote and the backend as the TV that actually shows the picture.