Skip to content

Commit

Permalink
chore(logging): Improved logs when using errors-only.
Browse files Browse the repository at this point in the history
  • Loading branch information
anthonyshew committed Jul 31, 2024
1 parent 75870c6 commit facc278
Showing 1 changed file with 35 additions and 10 deletions.
45 changes: 35 additions & 10 deletions crates/turborepo-lib/src/run/cache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)?;
}

Expand Down Expand Up @@ -205,6 +198,17 @@ impl TaskCache {
telemetry: &PackageTaskEventBuilder,
) -> Result<Option<CacheHitMetadata>, 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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit facc278

Please sign in to comment.