Skip to content

Commit

Permalink
don't write an error looking message when no line matches
Browse files Browse the repository at this point in the history
  • Loading branch information
Canop committed Dec 21, 2021
1 parent bc90754 commit 5b32567
Show file tree
Hide file tree
Showing 6 changed files with 15 additions and 10 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
<a name="v1.5.5"></a>
### v1.5.5 - 2021-12-21
- don't write an error when no log line matches the query

<a name="v1.5.4"></a>
### v1.5.4 - 2021-11-27
- fix compilation broken by patch release 1.0.49 of anyhow
Expand Down
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "rhit"
version = "1.5.4"
version = "1.5.5"
authors = ["dystroy <[email protected]>"]
repository = "https://github.com/Canop/rhit"
description = "nginx log analyzer"
Expand Down
4 changes: 0 additions & 4 deletions src/cli/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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))?;
Expand Down
7 changes: 6 additions & 1 deletion src/nginx_log/file_reader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(())
}
Expand Down
6 changes: 3 additions & 3 deletions src/nginx_log/log_base.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit 5b32567

Please sign in to comment.