mirror of
https://github.com/outbackdingo/firezone.git
synced 2026-01-27 10:18:54 +00:00
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
This commit is contained in:
@@ -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))
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user