Skip to content

Commit

Permalink
fix: log to file
Browse files Browse the repository at this point in the history
  • Loading branch information
galister committed Apr 10, 2024
1 parent 399168f commit 6e2c3fc
Showing 1 changed file with 15 additions and 8 deletions.
23 changes: 15 additions & 8 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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()?;
}
Expand Down

0 comments on commit 6e2c3fc

Please sign in to comment.