mirror of
https://github.com/lucaspalomodevelop/core.git
synced 2026-03-16 09:34:39 +00:00
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 dd6a04a68a, 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
This commit is contained in:
parent
8802b0ced1
commit
aba58e5ee4
@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user