Commit 82009e1e authored by Éloïs's avatar Éloïs

[feat] durs: add option log-stdout

parent c3f6783d
......@@ -43,6 +43,9 @@ pub struct DursOpt {
/// Set log level. (Defaults to INFO).
/// Available levels: [ERROR, WARN, INFO, DEBUG, TRACE]
logs_level: Option<Level>,
#[structopt(long = "log-stdout")]
/// Print logs in standard output
log_stdout: bool,
#[structopt(subcommand)]
/// CoreSubCommand
cmd: CoreSubCommand,
......
......@@ -775,6 +775,9 @@ pub fn init_logger(profile: &str, soft_name: &'static str, cli_args: &ArgMatches
_ => unreachable!("Structopt guarantees us that the string match necessarily with one of the variants of the enum Level"),
};
// Get log-stdout option
let log_stdout = cli_args.is_present("log_stdout");
// Config logger
let logger_config = Config {
time: Some(Level::Error),
......@@ -794,20 +797,28 @@ pub fn init_logger(profile: &str, soft_name: &'static str, cli_args: &ArgMatches
.expect("Fatal error : fail to create log file path !");
}
WriteLogger::init(
log_level.to_level_filter(),
logger_config,
OpenOptions::new()
.write(true)
.append(true)
.open(
log_file_path
.to_str()
.expect("Fatal error : fail to get log file path !"),
)
.expect("Fatal error : fail to open log file !"),
)
.expect("Fatal error : fail to init logger !");
let level_filter = log_level.to_level_filter();
let file_logger_opts = OpenOptions::new()
.write(true)
.append(true)
.open(
log_file_path
.to_str()
.expect("Fatal error : fail to get log file path !"),
)
.expect("Fatal error : fail to open log file !");
if log_stdout {
CombinedLogger::init(vec![
TermLogger::new(level_filter, logger_config)
.expect("Fatal error : fail to create term logger !"),
WriteLogger::new(level_filter, logger_config, file_logger_opts),
])
.expect("Fatal error : Fail to init combined logger !");
} else {
WriteLogger::init(level_filter, logger_config, file_logger_opts)
.expect("Fatal error : fail to init file logger !");
}
info!("Successfully init logger");
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment