From 65a4dc7f18b13175376ae83b34d802425777b97a Mon Sep 17 00:00:00 2001 From: Yasen Pramatarov Date: Fri, 21 Nov 2025 20:58:19 +0200 Subject: [PATCH] Introduces Log Throtter to prevent log flooding --- app/core/LogThrottler.php | 50 +++++++++++++++++++++++++++++++++++++++ public_html/index.php | 8 +++++-- 2 files changed, 56 insertions(+), 2 deletions(-) create mode 100644 app/core/LogThrottler.php diff --git a/app/core/LogThrottler.php b/app/core/LogThrottler.php new file mode 100644 index 0000000..721b171 --- /dev/null +++ b/app/core/LogThrottler.php @@ -0,0 +1,50 @@ +get($settingsKey); + if ($lastLogged) { + $lastTimestamp = strtotime($lastLogged); + if ($lastTimestamp !== false && (time() - $lastTimestamp) < $intervalSeconds) { + $shouldLog = false; + } + } + } catch (\Throwable $e) { + $settings = null; + } + + if ($shouldLog) { + $logger->log($level, $message, $context); + if ($settings) { + $settings->set($settingsKey, date('Y-m-d H:i:s')); + } + } + } +} diff --git a/public_html/index.php b/public_html/index.php index 7b3f38a..5e80777 100644 --- a/public_html/index.php +++ b/public_html/index.php @@ -168,6 +168,10 @@ require_once __DIR__ . '/../app/core/DatabaseConnector.php'; use App\Core\DatabaseConnector; $db = DatabaseConnector::connect($config); +// Initialize Log throttler +require_once __DIR__ . '/../app/core/LogThrottler.php'; +use App\Core\LogThrottler; + // Logging: default to NullLogger, plugin can override require_once __DIR__ . '/../app/core/NullLogger.php'; use App\Core\NullLogger; @@ -207,9 +211,9 @@ try { } } } - // Log and show as a system message only if not already added + // Log (throttled) and show as a system message only if not already added if (!$hasMigrationMessage) { - $logObject->log('warning', $msg, ['scope' => 'system']); + LogThrottler::logThrottled($logObject, $db, 'migrations_pending', 86400, 'warning', $msg, ['scope' => 'system']); Feedback::flash('SYSTEM', 'MIGRATIONS_PENDING', $msg, false, true, false); } }