29 lines
947 B
Rust
29 lines
947 B
Rust
use std::path::Path;
|
|
|
|
use ops_sat_rs::config::LOG_FOLDER;
|
|
|
|
pub fn setup_logger() -> Result<(), fern::InitError> {
|
|
if !Path::new(LOG_FOLDER).exists() && std::fs::create_dir_all(LOG_FOLDER).is_err() {
|
|
eprintln!("Failed to create log folder '{}'", LOG_FOLDER);
|
|
}
|
|
fern::Dispatch::new()
|
|
.format(move |out, message, record| {
|
|
out.finish(format_args!(
|
|
"[{}][{}][{}] {}",
|
|
humantime::format_rfc3339_millis(std::time::SystemTime::now()),
|
|
std::thread::current().name().unwrap_or("unnamed_thread"),
|
|
record.level(),
|
|
message
|
|
))
|
|
})
|
|
.level(log::LevelFilter::Debug)
|
|
.chain(std::io::stdout())
|
|
.chain(fern::log_file(format!(
|
|
"{}/output_{}.log",
|
|
LOG_FOLDER,
|
|
humantime::format_rfc3339_seconds(std::time::SystemTime::now())
|
|
))?)
|
|
.apply()?;
|
|
Ok(())
|
|
}
|