Add the tracing crate to Cargo.toml and initialize a subscriber to enable structured logging and diagnostics in Rust.
Add the tracing crate to your dependencies and initialize a subscriber in your main function to capture events.
[dependencies]
tracing = "0.1"
tracing-subscriber = "0.3"
use tracing::{info, Level};
use tracing_subscriber;
fn main() {
tracing_subscriber::fmt()
.with_max_level(Level::INFO)
.init();
info!("Application started");
}
The tracing crate lets you add lightweight logging and performance monitoring to your Rust code. It works like a dashboard for your application, showing you exactly what is happening inside your program without slowing it down. You use it whenever you need to debug issues or understand how long specific parts of your code take to run.