From aa2c57d898fd8cb4baaf4dbbcad18119e95e6398 Mon Sep 17 00:00:00 2001 From: zhiwuyazhe_fjr Date: Tue, 1 Dec 2026 20:21:57 +0800 Subject: [PATCH] fix(log): keep the latest distinct unclassified example --- src/cmds/system/log_cmd.rs | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/src/cmds/system/log_cmd.rs b/src/cmds/system/log_cmd.rs index cd2ca717e0..2beeda86f5 100644 --- a/src/cmds/system/log_cmd.rs +++ b/src/cmds/system/log_cmd.rs @@ -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; + } } } } @@ -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}" );