diff --git a/Cargo.lock b/Cargo.lock index aa4a6d875675c..6aca81d44ae1d 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -9138,6 +9138,7 @@ dependencies = [ "tempfile", "test-case", "thiserror", + "time 0.3.20", "tiny-gradient", "tokio", "tokio-stream", diff --git a/crates/turborepo-lib/Cargo.toml b/crates/turborepo-lib/Cargo.toml index 597b44671a6f2..b282d0f4f5a76 100644 --- a/crates/turborepo-lib/Cargo.toml +++ b/crates/turborepo-lib/Cargo.toml @@ -68,6 +68,7 @@ sha2 = "0.10.6" shared_child = "1.0.0" sysinfo = "0.27.7" thiserror = "1.0.38" +time = "0.3.20" tiny-gradient = { workspace = true } tokio = { workspace = true, features = ["full", "time"] } tokio-stream = { version = "0.1.12", features = ["net"] } diff --git a/crates/turborepo-lib/src/commands/daemon.rs b/crates/turborepo-lib/src/commands/daemon.rs index 09108756bd023..cab5d010cb1ee 100644 --- a/crates/turborepo-lib/src/commands/daemon.rs +++ b/crates/turborepo-lib/src/commands/daemon.rs @@ -1,6 +1,7 @@ use std::{path::PathBuf, time::Duration}; use pidlock::PidlockError::AlreadyOwned; +use time::{format_description, OffsetDateTime}; use tracing::{trace, warn}; use turbopath::{AbsoluteSystemPathBuf, RelativeSystemPathBuf}; @@ -44,9 +45,10 @@ pub async fn daemon_client(command: &DaemonCommand, base: &CommandBase) -> Resul } DaemonCommand::Status { json } => { let status = client.status().await?; + let log_file = log_filename(&status.log_file)?; let status = DaemonStatus { uptime_ms: status.uptime_msec, - log_file: status.log_file.into(), + log_file: log_file.into(), pid_file: client.pid_file().to_owned(), sock_file: client.sock_file().to_owned(), }; @@ -67,6 +69,16 @@ pub async fn daemon_client(command: &DaemonCommand, base: &CommandBase) -> Resul Ok(()) } +// log_filename matches the algorithm used by tracing_appender::Rotation::DAILY +// to generate the log filename. This is kind of a hack, but there didn't appear +// to be a simple way to grab the generated filename. +fn log_filename(base_filename: &str) -> Result { + let now = OffsetDateTime::now_utc(); + let format = format_description::parse("[year]-[month]-[day]")?; + let date = now.format(&format)?; + Ok(format!("{}.{}", base_filename, date)) +} + #[tracing::instrument(skip(base, logging), fields(repo_root = %base.repo_root))] pub async fn daemon_server( base: &CommandBase, diff --git a/crates/turborepo-lib/src/daemon/client.rs b/crates/turborepo-lib/src/daemon/client.rs index 0f0afc78b688f..40103681a1be0 100644 --- a/crates/turborepo-lib/src/daemon/client.rs +++ b/crates/turborepo-lib/src/daemon/client.rs @@ -152,6 +152,9 @@ pub enum DaemonError { #[error("unable to display output: {0}")] DisplayError(#[from] serde_json::Error), + + #[error("unable to construct log file name: {0}")] + InvalidLogFile(#[from] time::Error), } impl From for DaemonError {