diff --git a/rust/logging/src/file.rs b/rust/logging/src/file.rs index 3e8fcb390..5c1aa8ae1 100644 --- a/rust/logging/src/file.rs +++ b/rust/logging/src/file.rs @@ -19,11 +19,14 @@ use std::path::{Path, PathBuf}; use std::sync::Arc; use std::{fs, io}; +use anyhow::Context; use time::OffsetDateTime; use tracing::Subscriber; use tracing_appender::non_blocking::{NonBlocking, WorkerGuard}; use tracing_subscriber::Layer; +use crate::unwrap_or_debug; + pub const TIME_FORMAT: &str = "[year]-[month]-[day]-[hour]-[minute]-[second]"; /// How many lines we will at most buffer in the channel with the background thread that writes to disk. @@ -130,6 +133,7 @@ impl Appender { let filename = format!("{}.{date}.{}", self.file_base_name, self.file_extension); let path = self.directory.join(&filename); + let latest = self.directory.join("latest"); let mut open_options = fs::OpenOptions::new(); open_options.append(true).create(true); @@ -146,6 +150,21 @@ impl Appender { let file = new_file?; Self::set_permissions(&file)?; + let _ = std::fs::remove_file(&latest); + + #[cfg(unix)] + unwrap_or_debug!( + std::os::unix::fs::symlink(path, latest) + .context("Failed to create `latest` link to log file"), + "{}" + ); + #[cfg(windows)] + unwrap_or_debug!( + std::os::windows::fs::symlink_file(path, latest) + .context("Failed to create `latest` link to log file"), + "{}" + ); + Ok((file, filename)) }