From fdbb8c99df1c42a7e341ecde63c3e2686d6765af Mon Sep 17 00:00:00 2001 From: Bauke Date: Sat, 4 Nov 2023 15:35:54 +0100 Subject: [PATCH] Add an option to specify the log file. --- source/cli/mod.rs | 4 ++++ source/cli/run.rs | 4 ++-- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/source/cli/mod.rs b/source/cli/mod.rs index 740d71a..e511214 100644 --- a/source/cli/mod.rs +++ b/source/cli/mod.rs @@ -31,6 +31,10 @@ pub enum MainSubcommand { /// The data to log. #[arg(last = true)] data_to_log: Vec, + + /// The file to log to, it will be created if it doesn't exist. + #[arg(short, long, default_value = "bautils.log")] + file: String, }, } diff --git a/source/cli/run.rs b/source/cli/run.rs index 77bfc4d..06d6d7f 100644 --- a/source/cli/run.rs +++ b/source/cli/run.rs @@ -26,14 +26,14 @@ pub fn run() { } }, - Log { data_to_log } => { + Log { data_to_log, file } => { let log_line = format!( "{} {}", Utc::now().to_rfc3339_opts(SecondsFormat::Millis, true), data_to_log.join(" ") ); println!("{}", log_line); - append_line_to_file("log.txt", &log_line).unwrap(); + append_line_to_file(&file, &log_line).unwrap(); } } }