mirror of
https://codeberg.org/icewind/logsmash.git
synced 2026-06-03 18:14:11 +02:00
show unmatched by app
This commit is contained in:
parent
4bf687461f
commit
2ba2b82a4a
2 changed files with 22 additions and 12 deletions
|
|
@ -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<'_> {
|
||||||
|
|
|
||||||
19
src/main.rs
19
src/main.rs
|
|
@ -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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -81,11 +87,14 @@ fn main() -> MainResult {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
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(())
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue