mirror of
https://github.com/getnamingo/registry.git
synced 2025-05-17 01:57:00 +02:00
Further work on Monolog improvements
This commit is contained in:
parent
15652bad67
commit
595d10349c
7 changed files with 186 additions and 18 deletions
|
@ -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) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue