create logs in subfolder
This commit is contained in:
parent
45930a104b
commit
7da9e2364b
4
.gitignore
vendored
4
.gitignore
vendored
@ -4,4 +4,6 @@
|
||||
/.vscode
|
||||
# Ignore this, may include user specific paths.
|
||||
/.cargo/config.toml
|
||||
output.log
|
||||
|
||||
# Ignore logs folder generared by application.
|
||||
/logs
|
||||
|
@ -9,6 +9,7 @@ use std::path::{Path, PathBuf};
|
||||
|
||||
pub const STOP_FILE_NAME: &str = "stop-experiment";
|
||||
pub const HOME_FOLER_EXPERIMENT: &str = "/home/exp278";
|
||||
pub const LOG_FOLDER: &str = "logs";
|
||||
|
||||
pub const OBSW_SERVER_ADDR: Ipv4Addr = Ipv4Addr::UNSPECIFIED;
|
||||
pub const SERVER_PORT: u16 = 7301;
|
||||
|
@ -1,4 +1,11 @@
|
||||
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!(
|
||||
@ -12,7 +19,8 @@ pub fn setup_logger() -> Result<(), fern::InitError> {
|
||||
.level(log::LevelFilter::Debug)
|
||||
.chain(std::io::stdout())
|
||||
.chain(fern::log_file(format!(
|
||||
"output_{}.log",
|
||||
"{}/output_{}.log",
|
||||
LOG_FOLDER,
|
||||
humantime::format_rfc3339_seconds(std::time::SystemTime::now())
|
||||
))?)
|
||||
.apply()?;
|
||||
|
Loading…
Reference in New Issue
Block a user