From 128a9d9fad1d8c1d574bb64c072d8b66838f9717 Mon Sep 17 00:00:00 2001 From: Fu Wang Date: Sat, 17 Jan 2026 09:57:14 +0800 Subject: [PATCH] Enhance CLI Build Duration Output with Human-Readable Formatting (#4591) * Use humantime for build duration formatting in CLI Replaces manual millisecond formatting with humantime::format_duration for improved readability of build duration logs. Adds humantime as a dependency in Cargo.toml. * Format build duration with millisecond precision Changed build duration logging to use millisecond precision instead of default formatting to avoid microsecond/nanosecond noise. * Refactor duration formatting to use helper function to reduce code duplication. --------- Co-authored-by: Jonathan Kelley --- Cargo.lock | 1 + packages/cli/Cargo.toml | 1 + packages/cli/src/serve/runner.rs | 15 +++++++++++---- 3 files changed, 13 insertions(+), 4 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 56fbbfbc0..fb1a508c9 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -5521,6 +5521,7 @@ dependencies = [ "headers", "home", "html_parser", + "humantime", "hyper 1.8.1", "hyper-rustls 0.27.7", "hyper-util", diff --git a/packages/cli/Cargo.toml b/packages/cli/Cargo.toml index be5b4853e..13a0dcd5f 100644 --- a/packages/cli/Cargo.toml +++ b/packages/cli/Cargo.toml @@ -108,6 +108,7 @@ tracing-subscriber = { version = "0.3.19", features = [ "fmt", ] } console-subscriber = { version = "0.4.1", optional = true } +humantime = "2.2.0" tracing = { workspace = true } ansi-to-tui = { workspace = true } ansi-to-html = { workspace = true } diff --git a/packages/cli/src/serve/runner.rs b/packages/cli/src/serve/runner.rs index cc08901c7..f17cc40d3 100644 --- a/packages/cli/src/serve/runner.rs +++ b/packages/cli/src/serve/runner.rs @@ -604,13 +604,13 @@ impl AppServer { if self.client.builds_opened == 0 { tracing::info!( - "Build completed successfully in {GLOW_STYLE}{:?}ms{GLOW_STYLE:#}, launching app! 💫", - time_taken.as_millis() + "Build completed successfully in {GLOW_STYLE}{}{GLOW_STYLE:#}, launching app! 💫", + format_duration_ms(time_taken) ); } else { tracing::info!( - "Build completed in {GLOW_STYLE}{:?}ms{GLOW_STYLE:#}", - time_taken.as_millis() + "Build completed in {GLOW_STYLE}{}{GLOW_STYLE:#}", + format_duration_ms(time_taken) ); } @@ -1308,3 +1308,10 @@ fn is_wsl() -> bool { false } + +/// Format a Duration for human-readable output with millisecond precision. +fn format_duration_ms(d: Duration) -> String { + // Format duration with millisecond precision to avoid microsecond/nanosecond noise. + // See: https://github.com/chronotope/humantime/issues/35 + humantime::format_duration(Duration::from_millis(d.as_millis() as u64)).to_string() +}