From 8534ea3e295942183abc7089c22ea0f57a600bb0 Mon Sep 17 00:00:00 2001 From: wuyangji <694410194@qq.com> Date: Thu, 14 May 2026 03:33:42 +0800 Subject: [PATCH] =?UTF-8?q?fix(logs):=20=E4=BF=AE=E6=AD=A3=E6=B8=85?= =?UTF-8?q?=E7=90=86=E6=97=A5=E5=BF=97=E5=8D=95=E5=A4=8D=E6=95=B0=E6=96=87?= =?UTF-8?q?=E6=A1=88?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/cortex-cli/src/logs_cmd.rs | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/src/cortex-cli/src/logs_cmd.rs b/src/cortex-cli/src/logs_cmd.rs index f525efc3c..42f46db50 100644 --- a/src/cortex-cli/src/logs_cmd.rs +++ b/src/cortex-cli/src/logs_cmd.rs @@ -81,6 +81,10 @@ fn format_size(bytes: u64) -> String { } } +fn log_file_label(count: usize) -> &'static str { + if count == 1 { "log file" } else { "log files" } +} + impl LogsCli { /// Run the logs command. pub async fn run(self) -> Result<()> { @@ -344,8 +348,9 @@ impl LogsCli { if cleared > 0 { println!( - "Cleared {} log file(s) ({}) older than {} days.", + "Cleared {} {} ({}) older than {} days.", cleared, + log_file_label(cleared), format_size(cleared_bytes), self.keep_days ); @@ -406,6 +411,13 @@ mod tests { assert_eq!(format_size(MB), "1.00 MB"); } + #[test] + fn test_log_file_label() { + assert_eq!(log_file_label(0), "log files"); + assert_eq!(log_file_label(1), "log file"); + assert_eq!(log_file_label(2), "log files"); + } + // ========================================================================= // Tests for LogsCli default values // =========================================================================