Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
feat: new maxsizeLog parameter, and log::chunck in cronHourly
  • Loading branch information
Sekiro-kost committed Apr 30, 2024
commit c65fc28b218a5884cfa3951b74ea93f3f230aeb7
7 changes: 7 additions & 0 deletions core/class/jeedom.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}
}

/*************************************************************************************/
Expand Down
17 changes: 14 additions & 3 deletions core/class/log.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -140,19 +141,29 @@ 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;
}
$maxLineLog = self::getConfig('maxLineLog');
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) {
Expand Down
1 change: 1 addition & 0 deletions core/config/default.config.ini
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 6 additions & 0 deletions desktop/php/administration.php
Original file line number Diff line number Diff line change
Expand Up @@ -994,6 +994,12 @@
<input type="text" class="configKey form-control" data-l1key="maxLineLog">
</div>
</div>
<div class="form-group">
<label class="col-lg-4 col-md-4 col-sm-4 col-xs-3 control-label">{{Taille maximal pour fichier de log (en Mo)}}</label>
<div class="col-lg-3 col-md-4 col-sm-5 col-xs-6">
<input type="text" class="configKey form-control" data-l1key="maxSizeLog" />
</div>
</div>
<div class="form-group">
<label class="col-lg-4 col-md-4 col-sm-4 col-xs-3 control-label">{{Niveau de log par défaut}}</label>
<div class="col-lg-3 col-md-4 col-sm-5 col-xs-6">
Expand Down