From c65fc28b218a5884cfa3951b74ea93f3f230aeb7 Mon Sep 17 00:00:00 2001 From: Julien C Date: Tue, 30 Apr 2024 13:18:00 +0200 Subject: [PATCH 1/4] feat: new maxsizeLog parameter, and log::chunck in cronHourly --- core/class/jeedom.class.php | 7 +++++++ core/class/log.class.php | 17 ++++++++++++++--- core/config/default.config.ini | 1 + desktop/php/administration.php | 6 ++++++ 4 files changed, 28 insertions(+), 3 deletions(-) diff --git a/core/class/jeedom.class.php b/core/class/jeedom.class.php index b0d465631a..7945ec04b8 100644 --- a/core/class/jeedom.class.php +++ b/core/class/jeedom.class.php @@ -1293,6 +1293,13 @@ public static function cronHourly() { } catch (Error $e) { log::add('jeedom', 'error', $e->getMessage()); } + try{ + log::chunk('', 'hourly'); + }catch (Exception $e) { + log::add('jeedom', 'error', $e->getMessage()); + } catch (Error $e) { + log::add('jeedom', 'error', $e->getMessage()); + } } /*************************************************************************************/ diff --git a/core/class/log.class.php b/core/class/log.class.php index 7417b366a5..7e2c97f1f3 100644 --- a/core/class/log.class.php +++ b/core/class/log.class.php @@ -124,13 +124,14 @@ public static function add($_log, $_type, $_message, $_logicalId = '') { } } - public static function chunk($_log = '') { + public static function chunk($_log = '', $_callCronHourly = '') { $paths = array(); if ($_log != '') { $paths = array(self::getPathToLog($_log)); } else { $relativeLogPaths = array('', 'scenarioLog/'); foreach ($relativeLogPaths as $relativeLogPath) { + $logPath = self::getPathToLog($relativeLogPath); $logs = ls($logPath, '*'); foreach ($logs as $log) { @@ -140,12 +141,12 @@ public static function chunk($_log = '') { } foreach ($paths as $path) { if (is_file($path)) { - self::chunkLog($path); + self::chunkLog($path, $_callCronHourly = ''); } } } - public static function chunkLog($_path) { + public static function chunkLog($_path, $_callCronHourly = '') { if (strpos($_path, '.htaccess') !== false) { return; } @@ -153,6 +154,16 @@ public static function chunkLog($_path) { if ($maxLineLog < self::DEFAULT_MAX_LINE) { $maxLineLog = self::DEFAULT_MAX_LINE; } + if($_callCronHourly){ + $maxSizeLog = self::getConfig('maxSizeLog'); + if (filesize($_path) >= $maxSizeLog) { + try { + com_shell::execute(system::getCmdSudo() . 'chmod 664 ' . $_path . ' > /dev/null 2>&1;echo "$(tail -n ' . $maxLineLog . ' ' . $_path . ')" > ' . $_path); + } catch (\Exception $e) { + } + } + return; + } try { com_shell::execute(system::getCmdSudo() . 'chmod 664 ' . $_path . ' > /dev/null 2>&1;echo "$(tail -n ' . $maxLineLog . ' ' . $_path . ')" > ' . $_path); } catch (\Exception $e) { diff --git a/core/config/default.config.ini b/core/config/default.config.ini index 7bafc45386..7f66a9d2dc 100644 --- a/core/config/default.config.ini +++ b/core/config/default.config.ini @@ -78,6 +78,7 @@ security::whiteips = "127.0.0.1;192.168.*.*;10.*.*.*;172.*.*.*" ;Log maxLineLog = 500 +maxSizeLog = 5 log::level = 400 log::syslogudpport = 514 log::syslogudpfacility = user diff --git a/desktop/php/administration.php b/desktop/php/administration.php index ea1fb1a0a3..fc068bd201 100644 --- a/desktop/php/administration.php +++ b/desktop/php/administration.php @@ -994,6 +994,12 @@ +
+ +
+ +
+
From 7f77ef4940da5292f9d868b7dca5f30b40f432be Mon Sep 17 00:00:00 2001 From: Julien C Date: Tue, 30 Apr 2024 14:24:07 +0200 Subject: [PATCH 2/4] fix variableName and re clear chunkLog --- core/class/jeedom.class.php | 2 +- core/class/log.class.php | 26 +++++++++++++------------- 2 files changed, 14 insertions(+), 14 deletions(-) diff --git a/core/class/jeedom.class.php b/core/class/jeedom.class.php index 7945ec04b8..60d3119504 100644 --- a/core/class/jeedom.class.php +++ b/core/class/jeedom.class.php @@ -1294,7 +1294,7 @@ public static function cronHourly() { log::add('jeedom', 'error', $e->getMessage()); } try{ - log::chunk('', 'hourly'); + log::chunk('', $_onlyIfSizeExceeded = true); }catch (Exception $e) { log::add('jeedom', 'error', $e->getMessage()); } catch (Error $e) { diff --git a/core/class/log.class.php b/core/class/log.class.php index 7e2c97f1f3..c16e952469 100644 --- a/core/class/log.class.php +++ b/core/class/log.class.php @@ -124,7 +124,7 @@ public static function add($_log, $_type, $_message, $_logicalId = '') { } } - public static function chunk($_log = '', $_callCronHourly = '') { + public static function chunk($_log = '', $_onlyIfSizeExceeded = '') { $paths = array(); if ($_log != '') { $paths = array(self::getPathToLog($_log)); @@ -141,12 +141,22 @@ public static function chunk($_log = '', $_callCronHourly = '') { } foreach ($paths as $path) { if (is_file($path)) { - self::chunkLog($path, $_callCronHourly = ''); + if($_onlyIfSizeExceeded){ + $maxSizeLog = self::getConfig('maxSizeLog'); + if (filesize($_path) >= $maxSizeLog) { + try { + com_shell::execute(system::getCmdSudo() . 'chmod 664 ' . $_path . ' > /dev/null 2>&1;echo "$(tail -n ' . $maxLineLog . ' ' . $_path . ')" > ' . $_path); + } catch (\Exception $e) { + } + continue; + } + } + self::chunkLog($path); } } } - public static function chunkLog($_path, $_callCronHourly = '') { + public static function chunkLog($_path) { if (strpos($_path, '.htaccess') !== false) { return; } @@ -154,16 +164,6 @@ public static function chunkLog($_path, $_callCronHourly = '') { if ($maxLineLog < self::DEFAULT_MAX_LINE) { $maxLineLog = self::DEFAULT_MAX_LINE; } - if($_callCronHourly){ - $maxSizeLog = self::getConfig('maxSizeLog'); - if (filesize($_path) >= $maxSizeLog) { - try { - com_shell::execute(system::getCmdSudo() . 'chmod 664 ' . $_path . ' > /dev/null 2>&1;echo "$(tail -n ' . $maxLineLog . ' ' . $_path . ')" > ' . $_path); - } catch (\Exception $e) { - } - } - return; - } try { com_shell::execute(system::getCmdSudo() . 'chmod 664 ' . $_path . ' > /dev/null 2>&1;echo "$(tail -n ' . $maxLineLog . ' ' . $_path . ')" > ' . $_path); } catch (\Exception $e) { From 83ac82e3353b64342a687db7d5fe1820899b9c3d Mon Sep 17 00:00:00 2001 From: Julien C Date: Tue, 30 Apr 2024 14:49:34 +0200 Subject: [PATCH 3/4] fix code --- core/class/jeedom.class.php | 2 +- core/class/log.class.php | 19 ++++++------------- 2 files changed, 7 insertions(+), 14 deletions(-) diff --git a/core/class/jeedom.class.php b/core/class/jeedom.class.php index 60d3119504..23cb83b270 100644 --- a/core/class/jeedom.class.php +++ b/core/class/jeedom.class.php @@ -1294,7 +1294,7 @@ public static function cronHourly() { log::add('jeedom', 'error', $e->getMessage()); } try{ - log::chunk('', $_onlyIfSizeExceeded = true); + log::chunk('', True); }catch (Exception $e) { log::add('jeedom', 'error', $e->getMessage()); } catch (Error $e) { diff --git a/core/class/log.class.php b/core/class/log.class.php index c16e952469..f8909c7663 100644 --- a/core/class/log.class.php +++ b/core/class/log.class.php @@ -124,7 +124,7 @@ public static function add($_log, $_type, $_message, $_logicalId = '') { } } - public static function chunk($_log = '', $_onlyIfSizeExceeded = '') { + public static function chunk($_log = '', $_onlyIfSizeExceeded = False) { $paths = array(); if ($_log != '') { $paths = array(self::getPathToLog($_log)); @@ -140,19 +140,12 @@ public static function chunk($_log = '', $_onlyIfSizeExceeded = '') { } } foreach ($paths as $path) { - if (is_file($path)) { - if($_onlyIfSizeExceeded){ - $maxSizeLog = self::getConfig('maxSizeLog'); - if (filesize($_path) >= $maxSizeLog) { - try { - com_shell::execute(system::getCmdSudo() . 'chmod 664 ' . $_path . ' > /dev/null 2>&1;echo "$(tail -n ' . $maxLineLog . ' ' . $_path . ')" > ' . $_path); - } catch (\Exception $e) { - } + if (is_file($path)) { + if($_onlyIfSizeExceeded && filesize($path) < (self::getConfig('maxSizeLog') * 1024 * 1024) ){ continue; - } - } - self::chunkLog($path); - } + } + self::chunkLog($path); + } } } From e3c93edcee081696052ac397aca555e5097f9198 Mon Sep 17 00:00:00 2001 From: "Julien C." Date: Tue, 18 Mar 2025 11:29:36 +0100 Subject: [PATCH 4/4] Update administration.php --- desktop/php/administration.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/desktop/php/administration.php b/desktop/php/administration.php index fc068bd201..febd2d23ac 100644 --- a/desktop/php/administration.php +++ b/desktop/php/administration.php @@ -995,7 +995,7 @@
- +