From 421f8e76d6e53b0b0f0b6071370114dbf8f5e8ff Mon Sep 17 00:00:00 2001 From: Thomas Eizinger Date: Tue, 11 Mar 2025 01:16:58 +1100 Subject: [PATCH] feat(connlib): always symlink to latest log file (#8400) When debugging Firezone, it is useful to use `tail -f` on the current logfile to see what `connlib` is doing. This is quite annoying to do however because the log file rolls over with every restart of the application. As a small QoL improvement, we always symlink the latest log file to a link called `latest`. Therefore, all one needs to do is re-run the latest `tail -f ./latest` command to get the new logs. Resolves: #8388 --- rust/logging/src/file.rs | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) 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)) }