diff --git a/crates/turborepo-lib/src/run/cache.rs b/crates/turborepo-lib/src/run/cache.rs index 8e3eee1cc9a8c..4504206332f36 100644 --- a/crates/turborepo-lib/src/run/cache.rs +++ b/crates/turborepo-lib/src/run/cache.rs @@ -196,9 +196,10 @@ impl TaskCache { pub fn output_writer(&self, writer: W) -> Result, Error> { let mut log_writer = LogWriter::default(); - if !self.caching_disabled && !self.run_cache.writes_disabled { - log_writer.with_log_file(&self.log_file_path)?; - } + // We always write a log file even if we do not cache it. This would + // allow users to "stream" specific logs from a single task if the TUI + // was being used. + log_writer.with_log_file(&self.log_file_path)?; match self.task_output_logs { OutputLogsMode::None | OutputLogsMode::HashOnly | OutputLogsMode::ErrorsOnly => {} diff --git a/crates/turborepo-process/src/child.rs b/crates/turborepo-process/src/child.rs index c7d380ab3eb7d..6f2424920b29e 100644 --- a/crates/turborepo-process/src/child.rs +++ b/crates/turborepo-process/src/child.rs @@ -581,9 +581,18 @@ impl Child { let writer_fut = async { let mut result = Ok(()); - while let Some(bytes) = byte_rx.recv().await { - if let Err(err) = stdout_pipe.write_all(&bytes) { - result = Err(err); + loop { + match tokio::time::timeout(Duration::from_millis(200), byte_rx.recv()).await { + Ok(Some(bytes)) => { + result = stdout_pipe.write_all(&bytes); + } + Ok(None) => break, + Err(_) => { + // Flush the writer periodically if there hasn't been any new output + result = stdout_pipe.flush(); + } + } + if result.is_err() { break; } } diff --git a/crates/turborepo-ui/src/logs.rs b/crates/turborepo-ui/src/logs.rs index 6b7a4d7cfad67..a1f726f7eb288 100644 --- a/crates/turborepo-ui/src/logs.rs +++ b/crates/turborepo-ui/src/logs.rs @@ -38,7 +38,9 @@ impl LogWriter { Error::CannotWriteLogs(err) })?; - self.log_file = Some(BufWriter::new(log_file)); + // We keep the buffer smaller to ensure the log file does not too far behind the + // displayed logs. + self.log_file = Some(BufWriter::with_capacity(512, log_file)); Ok(()) }