Further work on Monolog improvements

This commit is contained in:
Pinga 2025-02-14 19:56:51 +02:00
parent 15652bad67
commit 595d10349c
7 changed files with 186 additions and 18 deletions

View file

@ -99,6 +99,13 @@ function setupLogger($logFilePath, $channelName = 'app') {
function archiveOldLogs($logFilePath) {
$logDir = dirname($logFilePath);
$backupDir = '/opt/backup';
$lockFile = $backupDir . '/log_archive.lock';
// Prevent multiple processes from running archive at the same time
if (file_exists($lockFile)) {
return; // Another process is already archiving
}
touch($lockFile); // Create lock file
if (!is_dir($backupDir)) {
mkdir($backupDir, 0755, true);
@ -116,12 +123,16 @@ function archiveOldLogs($logFilePath) {
// Open or create ZIP archive
$zip = new ZipArchive();
if ($zip->open($zipPath, ZipArchive::CREATE) === true) {
$zip->addFile($file, $filename);
if (!$zip->locateName($filename)) { // Prevent duplicate addition
$zip->addFile($file, $filename);
unlink($file); // Delete original log after archiving
}
$zip->close();
unlink($file); // Delete original log after archiving
}
}
}
unlink($lockFile); // Remove lock when done
}
function checkLogin($db, $clID, $pw) {