diff --git a/src/main.rs b/src/main.rs index cba4296..7fcc469 100644 --- a/src/main.rs +++ b/src/main.rs @@ -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, } fn main() -> Result<(), Box> { 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()?; }