use std::path::PathBuf;
use clap::Parser;
use torrust_tracker_deployer_lib::bootstrap::logging::{LogFormat, LogOutput, LoggingBuilder};
use tracing::{debug, error, info, trace, warn};
#[derive(Parser)]
#[command(name = "test_logging")]
#[command(about = "Test binary for logging configuration validation")]
struct Cli {
#[arg(long, value_enum)]
format: Option<LogFormat>,
#[arg(long, value_enum)]
file_format: Option<LogFormat>,
#[arg(long, value_enum)]
stderr_format: Option<LogFormat>,
#[arg(long, value_enum)]
output: LogOutput,
#[arg(long, default_value = "./data/logs")]
log_dir: PathBuf,
}
fn main() {
let cli = Cli::parse();
let mut builder = LoggingBuilder::new(&cli.log_dir).with_output(cli.output);
match (cli.format, cli.file_format, cli.stderr_format) {
(Some(format), None, None) => {
builder = builder.with_format(format);
}
(_, file_fmt, stderr_fmt) => {
if let Some(fmt) = file_fmt {
builder = builder.with_file_format(fmt);
}
if let Some(fmt) = stderr_fmt {
builder = builder.with_stderr_format(fmt);
}
}
}
builder.init();
trace!("This is a TRACE level message");
debug!("This is a DEBUG level message");
info!("This is an INFO level message");
warn!("This is a WARN level message");
error!("This is an ERROR level message");
std::thread::sleep(std::time::Duration::from_millis(50));
println!("LOGGING_TEST_COMPLETE");
}