Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Hack to get correct log file #4873

Merged
merged 1 commit into from May 8, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions crates/turborepo-lib/Cargo.toml
Expand Up @@ -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"] }
Expand Down
14 changes: 13 additions & 1 deletion 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};

Expand Down Expand Up @@ -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(),
};
Expand All @@ -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<String, time::Error> {
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,
Expand Down
3 changes: 3 additions & 0 deletions crates/turborepo-lib/src/daemon/client.rs
Expand Up @@ -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<Status> for DaemonError {
Expand Down