1
Fork 0

Add an option to specify the log file.

This commit is contained in:
Bauke 2023-11-04 15:35:54 +01:00
parent fae18669b2
commit fdbb8c99df
Signed by: Bauke
GPG Key ID: C1C0F29952BCF558
2 changed files with 6 additions and 2 deletions

View File

@ -31,6 +31,10 @@ pub enum MainSubcommand {
/// The data to log.
#[arg(last = true)]
data_to_log: Vec<String>,
/// The file to log to, it will be created if it doesn't exist.
#[arg(short, long, default_value = "bautils.log")]
file: String,
},
}

View File

@ -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();
}
}
}