-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
26 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
use crate::prelude::settings::run::Data; | ||
use log::LevelFilter; | ||
use log4rs::append::file::FileAppender; | ||
use log4rs::config::{Appender, Config, Root}; | ||
use log4rs::encode::pattern::PatternEncoder; | ||
use std::fs; | ||
|
||
pub fn setup_log(settings: &Data) { | ||
if let Some(log_path) = &settings.parsed.paths.log_out { | ||
if fs::remove_file(log_path).is_ok() {}; | ||
let logfile = FileAppender::builder() | ||
.encoder(Box::new(PatternEncoder::new("{l}: {m}\n"))) | ||
.build(log_path) | ||
.unwrap(); | ||
|
||
let config = Config::builder() | ||
.appender(Appender::builder().build("logfile", Box::new(logfile))) | ||
.build(Root::builder().appender("logfile").build(LevelFilter::Info)) | ||
.unwrap(); | ||
|
||
log4rs::init_config(config).unwrap(); | ||
}; | ||
} |