In software development, logs serve as a record of events within an application, providing crucial insights for debugging. When logging, it is essential to ensure that the logs are:
Those requirements are not met if a program directly writes to the standard outputs (e.g., print!, println!). That is why defining and using a dedicated logger is highly recommended.
fn do_something() {
println!("my message"); // Noncompliant, output directly to stdout without a logger
}
use log::{info, LevelFilter};
use simple_logger::SimpleLogger;
fn do_something() {
SimpleLogger::new().with_level(LevelFilter::Info).init().unwrap();
// ...
info!("my message"); // Compliant, output via logger
// ...
}