show unmatched by app

This commit is contained in:
Robin Appelman 2024-07-22 23:07:25 +02:00
commit 2ba2b82a4a
2 changed files with 22 additions and 12 deletions

View file

@ -8,6 +8,7 @@ pub struct LogLine<'a> {
pub level: LogLevel,
pub message: Cow<'a, str>,
pub exception: Option<Exception<'a>>,
pub app: Cow<'a, str>,
}
impl LogLine<'_> {

View file

@ -40,7 +40,8 @@ fn main() -> MainResult {
let lines = once(first).chain(lines);
let mut error_count = 0;
let mut unmatched = 0;
let mut unmatched_total = 0;
let mut unmatched = HashMap::new();
for line in lines {
if line.starts_with('{') {
let parsed = match serde_json::from_str::<LogLine>(&line) {
@ -53,7 +54,12 @@ fn main() -> MainResult {
if let Some(index) = matcher.match_log(&parsed) {
counts.entry(index).or_default().add_assign(1);
} else {
unmatched += 1;
unmatched_total += 1;
if let Some(entry) = unmatched.get_mut(parsed.app.as_ref()) {
*entry += 1;
} else {
unmatched.insert(parsed.app.to_string(), 1);
}
}
}
}
@ -81,11 +87,14 @@ fn main() -> MainResult {
);
}
}
if unmatched > 0 {
eprintln!("{unmatched} lines couldn't be matched");
if unmatched_total > 0 {
eprintln!("\n{unmatched_total} lines couldn't be matched:");
for (app, count) in unmatched {
eprintln!("\t{app}: {count}");
}
}
if error_count > 0 {
eprintln!("{error_count} lines failed to parse as valid log json");
eprintln!("\n{error_count} lines failed to parse as valid log json");
}
Ok(())