Add an option to specify the log file.
This commit is contained in:
parent
fae18669b2
commit
fdbb8c99df
|
@ -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,
|
||||
},
|
||||
}
|
||||
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue