-
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.
refact(jssp): store all run output in single directory instead of sin…
…gle file (#429) ## Description Multiple output files are now produced. Description can be found in ECDK docs.
- Loading branch information
Showing
5 changed files
with
70 additions
and
39 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,48 +1,52 @@ | ||
use std::path::Path; | ||
use std::{path::{Path, PathBuf}, collections::HashMap}; | ||
|
||
use log4rs::{ | ||
append::{console::ConsoleAppender, file::FileAppender}, | ||
config::{Appender, Logger}, | ||
encode::pattern::PatternEncoder, | ||
}; | ||
|
||
pub fn init_logging(log_file: Option<&Path>) -> Result<log4rs::Handle, log::SetLoggerError> { | ||
pub fn init_logging(log_files: &HashMap<String, PathBuf>) -> Result<log4rs::Handle, log::SetLoggerError> { | ||
let log_pattern = String::from("[{l}] {m}{n}"); | ||
let csv_log_pattern = String::from("{m}{n}"); | ||
|
||
let stdout_appender = ConsoleAppender::builder() | ||
.encoder(Box::new(PatternEncoder::new(&log_pattern))) | ||
.build(); | ||
|
||
let config = | ||
log4rs::Config::builder().appender(Appender::builder().build("main", Box::new(stdout_appender))); | ||
|
||
let config = if let Some(log_file) = log_file { | ||
let csv_appender = FileAppender::builder() | ||
.encoder(Box::new(PatternEncoder::new(&csv_log_pattern))) | ||
.append(false) | ||
.build(log_file) | ||
.unwrap(); | ||
config | ||
.appender(Appender::builder().build("csv_appender", Box::new(csv_appender))) | ||
.logger( | ||
Logger::builder() | ||
.appender("csv_appender") | ||
.additive(false) | ||
.build("csv", log::LevelFilter::Info), | ||
) | ||
} else { | ||
config | ||
}; | ||
|
||
let config = config | ||
let mut cfg_builder = log4rs::Config::builder(); | ||
|
||
// Register console appender | ||
cfg_builder = cfg_builder.appender(Appender::builder().build("main", Box::new(stdout_appender))); | ||
|
||
// Register appenders & loggers for given events | ||
if !log_files.is_empty() { | ||
let csv_encoder = Box::new(PatternEncoder::new(&csv_log_pattern)); | ||
for (event_name, log_file) in log_files.iter() { | ||
let csv_appender = FileAppender::builder() | ||
.encoder(csv_encoder.clone()) | ||
.append(false) | ||
.build(log_file) | ||
.unwrap(); | ||
|
||
cfg_builder = cfg_builder | ||
.appender(Appender::builder().build(event_name, Box::new(csv_appender))) | ||
.logger( | ||
Logger::builder() | ||
.appender(event_name) | ||
.additive(false) | ||
.build(event_name, log::LevelFilter::Info) | ||
); | ||
} | ||
} | ||
|
||
let config = cfg_builder | ||
.build( | ||
log4rs::config::Root::builder() | ||
.appender("main") | ||
.build(log::LevelFilter::Trace), | ||
) | ||
.unwrap(); | ||
// .appender(FileAppender::builder().encoder(Box::new(PatternEncoder::new(&csv_log_pattern))).build("log.txt")) | ||
|
||
log4rs::init_config(config) | ||
} |
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