From a7c6be4182218cf91bca5e2251bac5c49b5b5e8b Mon Sep 17 00:00:00 2001 From: DustInDark Date: Mon, 20 Dec 2021 01:13:23 +0900 Subject: [PATCH] added Quiet Errors option #309 --- src/detections/configs.rs | 1 + src/detections/print.rs | 17 +++++++++++++++-- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/src/detections/configs.rs b/src/detections/configs.rs index 908f1553..492f209e 100644 --- a/src/detections/configs.rs +++ b/src/detections/configs.rs @@ -68,6 +68,7 @@ fn build_app<'a>() -> ArgMatches<'a> { -t --thread-number=[NUMBER] 'Thread number (default: optimal number for performance)' -s --statistics 'Prints statistics of event IDs' -q --quiet 'Quiet mode. Do not display the launch banner' + -Q --quiet-errors 'Quiet errors mode. Do not display errors or save error logs' --contributors 'Prints the list of contributors'"; App::new(&program) .about("Hayabusa: Aiming to be the world's greatest Windows event log analysis tool!") diff --git a/src/detections/print.rs b/src/detections/print.rs index 7f64b400..d4b051ac 100644 --- a/src/detections/print.rs +++ b/src/detections/print.rs @@ -43,6 +43,11 @@ lazy_static! { "./logs/errorlog-{}.log", Local::now().format("%Y%m%d_%H%M%S") ); + pub static ref QUIERT_ERRORS_FLAG: bool = configs::CONFIG + .read() + .unwrap() + .args + .is_present("quiet-errors"); } #[derive(Copy, Clone)] @@ -235,12 +240,20 @@ impl AlertMessage { /// ERRORメッセージを表示する関数。error_log_flagでfalseの場合は外部へのエラーログの書き込みは行わずに指定されたwを用いた出力のみ行う。trueの場合はwを用いた出力を行わずにエラーログへの出力を行う pub fn alert(w: &mut W, contents: String) -> io::Result<()> { - writeln!(w, "[ERROR] {}", contents) + if QUIERT_ERRORS_FLAG { + writeln!(w, "[ERROR] {}", contents) + } else { + ok() + } } // WARNメッセージを表示する関数 pub fn warn(w: &mut W, contents: String) -> io::Result<()> { - writeln!(w, "[WARN] {}", contents) + if QUIERT_ERRORS_FLAG { + writeln!(w, "[WARN] {}", contents) + } else { + ok() + } } /// エラーログへのERRORメッセージの出力数を確認して、0であったらファイルを削除する。1以上あればエラーを書き出した旨を標準出力に表示する