added output error log remove feature by line count #301

This commit is contained in:
DustInDark
2021-12-20 00:40:41 +09:00
parent a1c3bd0596
commit 3b7cf0b948
3 changed files with 12 additions and 3 deletions

7
Cargo.lock generated
View File

@@ -773,6 +773,7 @@ dependencies = [
"hashbrown",
"hhmmss",
"lazy_static",
"linecount",
"linked-hash-map",
"mopa",
"num_cpus",
@@ -1015,6 +1016,12 @@ version = "0.2.102"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a2a5ac8f984bfcf3a823267e5fde638acc3325f6496633a5da6bb6eb2171e103"
[[package]]
name = "linecount"
version = "0.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d5d5a4a243b9cf052d37af99679cc93b08a791f444a4a1b21bb4efcaf01847d8"
[[package]]
name = "linked-hash-map"
version = "0.5.3"

View File

@@ -29,6 +29,7 @@ dotenv = "0.15.0"
hhmmss = "*"
pbr = "*"
hashbrown = "0.11.2"
linecount = "*"
[target.x86_64-pc-windows-gnu]
linker = "x86_64-w64-mingw32-gcc"

View File

@@ -4,6 +4,7 @@ use crate::detections::utils;
use crate::detections::utils::get_serde_number_to_string;
use chrono::{DateTime, Local, TimeZone, Utc};
use lazy_static::lazy_static;
use linecount::count_lines;
use regex::Regex;
use serde_json::Value;
use std::collections::BTreeMap;
@@ -250,19 +251,19 @@ impl AlertMessage {
/// エラーログへのERRORメッセージの出力数を確認して、0であったらファイルを削除する。1以上あればエラーを書き出した旨を標準出力に表示する
pub fn output_error_log_exist() {
let error_log_path_str = ERROR_LOG_PATH.to_string();
if ALERT_COUNT_IN_ERROR_LOG.lock().unwrap().count == 0 {
// 1行しかなかった場合は最初に書いたコマンド情報のみと判断して削除する
if count_lines(File::open(&error_log_path_str).unwrap()).unwrap() == 1 {
if remove_file(&error_log_path_str).is_err() {
AlertMessage::alert(
&mut std::io::stderr().lock(),
format!("failed to remove file. filepath:{}", &error_log_path_str),
false,
)
.ok();
}
return;
}
println!(
"Generated error was output to {}. Please see the file for details",
"Generated error was output to {}. Please see the file for details.",
&error_log_path_str
);
}