use fstdout_logger::{LoggerConfig, init_logger_with_config};
use log::{LevelFilter, debug, error, info, trace, warn};
use std::thread::sleep;
use std::time::Duration;
fn main() {
let log_path = "application.log";
let config = LoggerConfig::builder()
.level(LevelFilter::Trace) .show_file_info(true) .show_date_in_stdout(false) .use_colors(true) .build();
if let Err(e) = init_logger_with_config(Some(log_path), config) {
eprintln!("Failed to initialize logger: {e}");
return;
}
println!("Logger initialized! Check {log_path} for log output.");
println!("Log messages will appear both on stdout and in the log file.");
println!("Notice that stdout logs show time only while the file includes dates.");
trace!("This is a TRACE message"); debug!("This is a DEBUG message"); info!("This is an INFO message"); warn!("This is a WARNING message"); error!("This is an ERROR message");
for i in 1..=5 {
info!("Application is running... iteration {i}");
sleep(Duration::from_millis(500));
}
info!("Application finished successfully");
println!("\nAfter running this example, check the 'application.log' file");
println!("to see how logs are formatted differently for file output.");
}