From facc278b841b199aa5ec69d6426ccdd5b2831e72 Mon Sep 17 00:00:00 2001 From: Anthony Shew Date: Tue, 30 Jul 2024 23:08:52 -0600 Subject: [PATCH 1/2] chore(logging): Improved logs when using errors-only. --- crates/turborepo-lib/src/run/cache.rs | 45 +++++++++++++++++++++------ 1 file changed, 35 insertions(+), 10 deletions(-) diff --git a/crates/turborepo-lib/src/run/cache.rs b/crates/turborepo-lib/src/run/cache.rs index 3366d451f41a5..96a79b1cb7e9b 100644 --- a/crates/turborepo-lib/src/run/cache.rs +++ b/crates/turborepo-lib/src/run/cache.rs @@ -162,13 +162,6 @@ impl TaskCache { pub fn on_error(&self, terminal_output: &mut impl CacheOutput) -> Result<(), Error> { if self.task_output_logs == OutputLogsMode::ErrorsOnly { - terminal_output.status( - &format!( - "cache miss, executing {}", - color!(self.ui, GREY, "{}", self.hash) - ), - CacheResult::Miss, - ); self.replay_log_file(terminal_output)?; } @@ -205,6 +198,17 @@ impl TaskCache { telemetry: &PackageTaskEventBuilder, ) -> Result, Error> { if self.caching_disabled || self.run_cache.reads_disabled { + if matches!(self.task_output_logs, OutputLogsMode::ErrorsOnly) { + terminal_output.status( + &format!( + "cache bypass, force executing {} {}", + color!(self.ui, GREY, "{}", self.hash), + color!(self.ui, GREY, "{}", "(only logging errors)") + ), + CacheResult::Miss, + ); + } + if !matches!( self.task_output_logs, OutputLogsMode::None | OutputLogsMode::ErrorsOnly @@ -256,6 +260,17 @@ impl TaskCache { .await?; let Some((cache_hit_metadata, restored_files)) = cache_status else { + if matches!(self.task_output_logs, OutputLogsMode::ErrorsOnly) { + terminal_output.status( + &format!( + "cache miss, executing {} {}", + color!(self.ui, GREY, "{}", self.hash), + color!(self.ui, GREY, "{}", "(only logging errors)") + ), + CacheResult::Miss, + ); + } + if !matches!( self.task_output_logs, OutputLogsMode::None | OutputLogsMode::ErrorsOnly @@ -332,9 +347,19 @@ impl TaskCache { ); self.replay_log_file(terminal_output)?; } - // Note that if we're restoring from cache, the task succeeded - // so we know we don't need to print anything for errors - OutputLogsMode::ErrorsOnly | OutputLogsMode::None => {} + OutputLogsMode::ErrorsOnly => { + debug!("log file path: {}", self.log_file_path); + terminal_output.status( + &format!( + "cache hit{}, replaying logs {} {}", + more_context, + color!(self.ui, GREY, "{}", self.hash), + color!(self.ui, GREY, "{}", "(no errors in logs)") + ), + CacheResult::Hit, + ); + } + OutputLogsMode::None => {} } Ok(cache_status) From d58d83d960871562a70d9b2715f568a6fc4db55d Mon Sep 17 00:00:00 2001 From: Anthony Shew Date: Tue, 30 Jul 2024 23:34:09 -0600 Subject: [PATCH 2/2] Fix tests. --- turborepo-tests/integration/tests/run-logging/errors-only.t | 6 ++++-- .../integration/tests/run/single-package/with-deps-run.t | 2 ++ 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/turborepo-tests/integration/tests/run-logging/errors-only.t b/turborepo-tests/integration/tests/run-logging/errors-only.t index 403f3aa02343d..edc644cd53a7e 100644 --- a/turborepo-tests/integration/tests/run-logging/errors-only.t +++ b/turborepo-tests/integration/tests/run-logging/errors-only.t @@ -8,6 +8,7 @@ Setup \xe2\x80\xa2 Packages in scope: app-a (esc) \xe2\x80\xa2 Running build in 1 packages (esc) \xe2\x80\xa2 Remote caching disabled (esc) + app-a:build: cache miss, executing 612027951a2848ce (only logging errors) Tasks: 1 successful, 1 total Cached: 0 cached, 1 total @@ -23,6 +24,7 @@ Setup \xe2\x80\xa2 Packages in scope: app-a (esc) \xe2\x80\xa2 Running buildsuccess in 1 packages (esc) \xe2\x80\xa2 Remote caching disabled (esc) + app-a:buildsuccess: cache miss, executing 7ac84282f5a5b151 (only logging errors) Tasks: 1 successful, 1 total Cached: 0 cached, 1 total @@ -37,7 +39,7 @@ Setup \xe2\x80\xa2 Packages in scope: app-a (esc) \xe2\x80\xa2 Running builderror in 1 packages (esc) \xe2\x80\xa2 Remote caching disabled (esc) - app-a:builderror: cache miss, executing 7e337a3261100818 + app-a:builderror: cache miss, executing 7e337a3261100818 (only logging errors) app-a:builderror: app-a:builderror: > builderror app-a:builderror: > echo error-builderror-app-a && exit 1 @@ -67,7 +69,7 @@ Setup \xe2\x80\xa2 Packages in scope: app-a (esc) \xe2\x80\xa2 Running builderror2 in 1 packages (esc) \xe2\x80\xa2 Remote caching disabled (esc) - app-a:builderror2: cache miss, executing 3731518fa339b920 + app-a:builderror2: cache miss, executing 3731518fa339b920 (only logging errors) app-a:builderror2: app-a:builderror2: > builderror2 app-a:builderror2: > echo error-builderror2-app-a && exit 1 diff --git a/turborepo-tests/integration/tests/run/single-package/with-deps-run.t b/turborepo-tests/integration/tests/run/single-package/with-deps-run.t index 0050f76b42fcf..8ce6cdf71c4aa 100644 --- a/turborepo-tests/integration/tests/run/single-package/with-deps-run.t +++ b/turborepo-tests/integration/tests/run/single-package/with-deps-run.t @@ -56,6 +56,8 @@ Run with --output-logs=errors-only $ ${TURBO} run test --output-logs=errors-only \xe2\x80\xa2 Running test (esc) \xe2\x80\xa2 Remote caching disabled (esc) + build: cache hit, replaying logs 7ece7b62aad25615 (no errors in logs) + test: cache hit, replaying logs cb5839f7284aa5f3 (no errors in logs) Tasks: 2 successful, 2 total Cached: 2 cached, 2 total