Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 10 additions & 4 deletions src/cmds/system/log_cmd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -112,8 +112,13 @@ fn analyze_logs(content: &str) -> String {
*info_counts.entry(normalized).or_insert(0) += 1;
} else if !line.trim().is_empty() {
unclassified_count += 1;
if examples.len() < MAX_OTHER_EXAMPLES && !examples.contains(&line) {
examples.push(line);
if !examples.contains(&line) {
if examples.len() < MAX_OTHER_EXAMPLES {
examples.push(line);
} else if let Some(last) = examples.last_mut() {
// Keep the opening context and the latest distinct outcome in the same budget.
*last = line;
}
}
}
}
Expand Down Expand Up @@ -263,13 +268,14 @@ mod tests {
for id in 1..=40 {
log.push_str(&format!("api-log-line\nrequest served id={id}\n"));
}
log.push_str("shutdown complete, exit status 3\napi-log-line\nINFO stopped\n");
let result = run_stdin_str(&log);
assert!(
result.ends_with(concat!(
" [other] 80 unclassified lines\n",
" [other] 82 unclassified lines\n",
" api-log-line\n",
" request served id=1\n",
" request served id=2\n",
" shutdown complete, exit status 3\n",
)),
"{result}"
);
Expand Down
Loading