fix: log to file

This commit is contained in:
galister
2024-04-10 14:57:23 +09:00
parent 399168fc38
commit 6e2c3fc523

View File

@@ -9,9 +9,12 @@ mod overlays;
mod shaders;
mod state;
use std::sync::{
atomic::{AtomicBool, Ordering},
Arc,
use std::{
path::PathBuf,
sync::{
atomic::{AtomicBool, Ordering},
Arc,
},
};
use clap::Parser;
@@ -36,18 +39,22 @@ struct Args {
uninstall: bool,
/// Path to write logs to
#[arg(short, long, value_name = "FOLDER")]
#[arg(short, long, value_name = "FILE_PATH")]
log_to: Option<String>,
}
fn main() -> Result<(), Box<dyn std::error::Error>> {
let args = Args::parse();
if let Some(ref log_to) = args.log_to {
let maybe_logfile = std::env::var("WLX_LOGFILE").ok();
if let Some(ref log_to) = args.log_to.as_ref().or(maybe_logfile.as_ref()) {
let file_spec = FileSpec::try_from(PathBuf::from(log_to))?;
flexi_logger::Logger::try_with_env_or_str("info")?
.log_to_file(FileSpec::default().directory(log_to))
.log_to_stdout()
.log_to_file(file_spec)
.duplicate_to_stderr(flexi_logger::Duplicate::Info)
.start()?;
println!("Logging to: {}", &log_to);
println!(" ****** Logging to: {} ******", &log_to);
println!(" ****** Console logs limited to Info ******");
} else {
flexi_logger::Logger::try_with_env_or_str("info")?.start()?;
}