From 452886ea3ac4b91bc72952df659fb53ae7807c22 Mon Sep 17 00:00:00 2001 From: Kevin Papst Date: Sat, 9 Dec 2017 13:52:05 +0100 Subject: incorporated code review feedback --- constants.php | 3 +++ lib/Minz/Log.php | 7 +++---- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/constants.php b/constants.php index 9c647eb74..b48c1be96 100644 --- a/constants.php +++ b/constants.php @@ -8,6 +8,9 @@ define('FRESHRSS_USERAGENT', 'FreshRSS/' . FRESHRSS_VERSION . ' (' . PHP_OS . '; // PHP text output compression http://php.net/ob_gzhandler (better to do it at Web server level) define('PHP_COMPRESSION', false); +// maximum log file size, before it will be purged (defaults to 512000 = 500kB) +define('MAX_LOG_SIZE', 512000); + // Constantes de chemins define('FRESHRSS_PATH', dirname(__FILE__)); diff --git a/lib/Minz/Log.php b/lib/Minz/Log.php index f7029f47d..6231754fa 100644 --- a/lib/Minz/Log.php +++ b/lib/Minz/Log.php @@ -20,8 +20,6 @@ class Minz_Log { const NOTICE = 8; const DEBUG = 16; - const MAX_LOG_SIZE = 512000; // 500kB - /** * Enregistre un message dans un fichier de log spécifique * Message non loggué si @@ -91,8 +89,9 @@ class Minz_Log { * @throws Minz_PermissionDeniedException */ protected static function checkLogfileSize($file_name) { - if (file_exists($file_name) && filesize($file_name) > self::MAX_LOG_SIZE) { - if (!unlink($file_name)) { + $maxSize = defined('MAX_LOG_SIZE') ? MAX_LOG_SIZE : 512000; + if (@filesize($file_name) > $maxSize) { + if (file_put_contents($file_name, '') === false) { throw new Minz_PermissionDeniedException($file_name, Minz_Exception::ERROR); } } -- cgit v1.2.3