diff --git a/CHANGELOG.md b/CHANGELOG.md index 010882a..60570ec 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,7 @@ + +### v1.5.5 - 2021-12-21 +- don't write an error when no log line matches the query + ### v1.5.4 - 2021-11-27 - fix compilation broken by patch release 1.0.49 of anyhow diff --git a/Cargo.lock b/Cargo.lock index 814eb75..e4d198b 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -897,7 +897,7 @@ dependencies = [ [[package]] name = "rhit" -version = "1.5.4" +version = "1.5.5" dependencies = [ "anyhow", "argh", diff --git a/Cargo.toml b/Cargo.toml index 18be7a1..89b69f1 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "rhit" -version = "1.5.4" +version = "1.5.5" authors = ["dystroy "] repository = "https://github.com/Canop/rhit" description = "nginx log analyzer" diff --git a/src/cli/mod.rs b/src/cli/mod.rs index ac20841..67d201d 100644 --- a/src/cli/mod.rs +++ b/src/cli/mod.rs @@ -11,10 +11,6 @@ use { fn print_analysis(path: &Path, args: &args::Args) -> Result<()> { let mut log_base = time!("LogBase::new", LogBase::new(path, args))?; - if log_base.lines.is_empty() { - eprintln!("no hit in logs"); - return Ok(()); - } let printer = md::Printer::new(args, &log_base); let base = &mut log_base; let trend_computer = time!("Trend computer initialization", TrendComputer::new(base, args))?; diff --git a/src/nginx_log/file_reader.rs b/src/nginx_log/file_reader.rs index d1ca80d..578aaf5 100644 --- a/src/nginx_log/file_reader.rs +++ b/src/nginx_log/file_reader.rs @@ -137,7 +137,12 @@ impl<'c, C: LineConsumer> FileReader<'c, C> { } execute!(io::stderr(), Clear(ClearType::CurrentLine))?; if !self.silent { - eprintln!("I've read {} files in {:?}", total, self.root); + eprintln!( + "I've read {} file{} in {:?}", + total, + if total > 1 { "s" } else { "" }, + self.root, + ); } Ok(()) } diff --git a/src/nginx_log/log_base.rs b/src/nginx_log/log_base.rs index 4a0c20d..151bbd8 100644 --- a/src/nginx_log/log_base.rs +++ b/src/nginx_log/log_base.rs @@ -69,15 +69,15 @@ impl LogBase { time!("reading files", file_reader.read_all_files())?; let filterer = file_reader.filterer(); let BaseContent {lines, unfiltered_histogram, filtered_histogram, ..} = base_content; - if lines.is_empty() { - bail!("no log file found in {:?}", path); - } let mut unfiltered_count = 0; let mut dates = Vec::new(); for bar in &unfiltered_histogram.bars { unfiltered_count += bar.hits; dates.push(bar.date); } + if unfiltered_count == 0 { + bail!("no hit found in {:?}", path); + } let filtered_count = filtered_histogram.total_hits(); Ok(Self { dates,