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); } }