From aba58e5ee455c0639e93dff8e67b33ecaef50185 Mon Sep 17 00:00:00 2001 From: Ad Schellevis Date: Thu, 18 Nov 2021 17:06:40 +0100 Subject: [PATCH] Logging: Add a symlink for e.g. system.log to system_todaysdate.log for log parsing (https://github.com/opnsense/core/issues/4993) same same as https://github.com/opnsense/core/commit/dd6a04a68a73f42cc1a6a63cebe568a6f6287bab, but different. Concerns fixed in this commit: o archive shouldn't generate files so old "archived" files remain untouched o "latest.log" should point to the latest version know, which could be todays or a file from the past o better to not remove links when unchanged to prevent excessive writes --- src/opnsense/scripts/syslog/log_archive | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/opnsense/scripts/syslog/log_archive b/src/opnsense/scripts/syslog/log_archive index 5f45a45ad..69e0b31da 100755 --- a/src/opnsense/scripts/syslog/log_archive +++ b/src/opnsense/scripts/syslog/log_archive @@ -54,17 +54,17 @@ foreach(new RecursiveIteratorIterator($it) as $file) { // remove expired logs and set latest.log symlink foreach ($relevant_logs as $log_subject => $items) { + rsort($items); if (count($items) > $preserve_logs) { - rsort($items); foreach (array_slice($items, $preserve_logs) as $filename) { @unlink($filename); } } - - $target = "/var/log/{$log_subject}/{$log_subject}_" . date('Ymd') . '.log'; - $link = "/var/log/{$log_subject}/latest.log"; - - @touch($target); - @unlink($link); - @symlink($target, $link); + // latest is always top of rsorted list $items[0] + $current_target = @readlink($link); + if ($current_target != $items[0]) { + $link = "/var/log/{$log_subject}/latest.log"; + @unlink($link); + @symlink($items[0], $link); + } }