How to Log Errors in Rust (tracing, log crates)

Add tracing and tracing-subscriber to Cargo.toml, initialize the subscriber in main, and use macros like info! and error! to log messages.

Add the tracing and tracing-subscriber crates to your Cargo.toml and initialize the subscriber in main to capture logs.

[dependencies]
tracing = "0.1"
tracing-subscriber = "0.3"
use tracing::{info, error, Level};
use tracing_subscriber;

fn main() {
    tracing_subscriber::fmt()
        .with_max_level(Level::INFO)
        .init();

    info!("Application started");
    error!("Something went wrong");
}