added logging directories with date
This commit is contained in:
parent
60e4af435a
commit
cbdb017fe2
1
Cargo.lock
generated
1
Cargo.lock
generated
@ -613,6 +613,7 @@ dependencies = [
|
|||||||
"log",
|
"log",
|
||||||
"mio",
|
"mio",
|
||||||
"num_enum",
|
"num_enum",
|
||||||
|
"once_cell",
|
||||||
"satrs",
|
"satrs",
|
||||||
"satrs-mib",
|
"satrs-mib",
|
||||||
"serde",
|
"serde",
|
||||||
|
@ -21,6 +21,7 @@ serde_json = "1"
|
|||||||
mio = "0.8"
|
mio = "0.8"
|
||||||
homedir = "0.2"
|
homedir = "0.2"
|
||||||
socket2 = "0.5"
|
socket2 = "0.5"
|
||||||
|
once_cell = "1.19"
|
||||||
|
|
||||||
[dependencies.satrs]
|
[dependencies.satrs]
|
||||||
version = "0.2.0-rc.5"
|
version = "0.2.0-rc.5"
|
||||||
|
@ -1,13 +1,17 @@
|
|||||||
use std::path::{Path, PathBuf};
|
use std::path::{Path, PathBuf};
|
||||||
|
use once_cell::sync::OnceCell;
|
||||||
use ops_sat_rs::config::LOG_FOLDER;
|
use ops_sat_rs::config::LOG_FOLDER;
|
||||||
|
|
||||||
|
pub static LOGFILE_PATH: OnceCell<PathBuf> = OnceCell::new();
|
||||||
|
|
||||||
pub fn setup_logger() -> Result<(), fern::InitError> {
|
pub fn setup_logger() -> Result<(), fern::InitError> {
|
||||||
if !Path::new(LOG_FOLDER).exists() && std::fs::create_dir_all(LOG_FOLDER).is_err() {
|
if !Path::new(LOG_FOLDER).exists() && std::fs::create_dir_all(LOG_FOLDER).is_err() {
|
||||||
eprintln!("Failed to create log folder '{}'", LOG_FOLDER);
|
eprintln!("Failed to create log folder '{}'", LOG_FOLDER);
|
||||||
}
|
}
|
||||||
let mut path_buf = PathBuf::from(LOG_FOLDER);
|
let mut path_buf = PathBuf::from(LOG_FOLDER);
|
||||||
path_buf.push("output.log");
|
path_buf.push(format!("output_{}.log", humantime::format_rfc3339_seconds(std::time::SystemTime::now()).to_string()).replace(":", "_"));
|
||||||
|
println!("Creating logfile {:?}", path_buf);
|
||||||
|
LOGFILE_PATH.set(path_buf.clone()).expect("Error setting global logfile path");
|
||||||
fern::Dispatch::new()
|
fern::Dispatch::new()
|
||||||
.format(move |out, message, record| {
|
.format(move |out, message, record| {
|
||||||
out.finish(format_args!(
|
out.finish(format_args!(
|
||||||
|
Loading…
Reference in New Issue
Block a user