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 level: LogLevel,
pub message: Cow<'a, str>, pub message: Cow<'a, str>,
pub exception: Option<Exception<'a>>, pub exception: Option<Exception<'a>>,
pub app: Cow<'a, str>,
} }
impl LogLine<'_> { impl LogLine<'_> {

View file

@ -40,7 +40,8 @@ fn main() -> MainResult {
let lines = once(first).chain(lines); let lines = once(first).chain(lines);
let mut error_count = 0; let mut error_count = 0;
let mut unmatched = 0; let mut unmatched_total = 0;
let mut unmatched = HashMap::new();
for line in lines { for line in lines {
if line.starts_with('{') { if line.starts_with('{') {
let parsed = match serde_json::from_str::<LogLine>(&line) { let parsed = match serde_json::from_str::<LogLine>(&line) {
@ -53,7 +54,12 @@ fn main() -> MainResult {
if let Some(index) = matcher.match_log(&parsed) { if let Some(index) = matcher.match_log(&parsed) {
counts.entry(index).or_default().add_assign(1); counts.entry(index).or_default().add_assign(1);
} else { } 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);
}
} }
} }
} }
@ -72,20 +78,23 @@ fn main() -> MainResult {
count count
); );
} else { } else {
println!( println!(
"{}: {} line {}: {}", "{}: {} line {}: {}",
statement.message(), statement.message(),
statement.path, statement.path,
statement.line, statement.line,
count count
); );
} }
} }
if unmatched > 0 { if unmatched_total > 0 {
eprintln!("{unmatched} lines couldn't be matched"); eprintln!("\n{unmatched_total} lines couldn't be matched:");
for (app, count) in unmatched {
eprintln!("\t{app}: {count}");
}
} }
if error_count > 0 { 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(()) Ok(())