Fix output message in log rotation job

This commit is contained in:
Laurent Destailleur 2018-03-21 13:56:24 +01:00
parent 7e5c3cc807
commit 200fd88132
2 changed files with 15 additions and 11 deletions

View File

@ -676,7 +676,7 @@ class Utils
* This saves syslog files and compresses older ones
* Used from cronjob
*
* @return int 0 if OK, < 0 if KO
* @return int 0 if OK, < 0 if KO
*/
function compressSyslogs() {
global $conf;
@ -686,6 +686,7 @@ class Utils
}
if(! function_exists('gzopen')) {
$this->error = 'Support for gzopen not available in this PHP';
return -1;
}
@ -693,7 +694,7 @@ class Utils
$nbSaves = ! empty($conf->global->SYSLOG_FILE_SAVES) ? intval($conf->global->SYSLOG_FILE_SAVES) : 14;
if(empty($conf->global->SYSLOG_FILE)) {
if (empty($conf->global->SYSLOG_FILE)) {
$mainlogdir = DOL_DATA_ROOT;
$mainlog = 'dolibarr.log';
} else {
@ -710,7 +711,7 @@ class Utils
$logname = $file['name'];
$logpath = $file['path'];
// Handle already compressed files
// Handle already compressed files to rename them and add +1
$filter = '^'.preg_quote($logname, '/').'\.([0-9]+)\.gz$';
@ -729,7 +730,7 @@ class Utils
krsort($gzfiles, SORT_NUMERIC);
foreach($gzfiles as $numsave => $dummy) {
if(dol_is_file($logpath.'/'.$logname.'.'.($numsave+1).'.gz')) {
if (dol_is_file($logpath.'/'.$logname.'.'.($numsave+1).'.gz')) {
return -2;
}
@ -741,18 +742,19 @@ class Utils
}
// Compress last save
if(dol_is_file($logpath.'/'.$logname.'.1')) {
if (dol_is_file($logpath.'/'.$logname.'.1')) {
if($nbSaves > 1) {
$gzfilehandle = gzopen($logpath.'/'.$logname.'.2.gz', 'wb9');
if(empty($gzfilehandle)) {
if (empty($gzfilehandle)) {
$this->error = 'Failted to open file '.$logpath.'/'.$logname.'.2.gz';
return -3;
}
$sourcehandle = fopen($logpath.'/'.$logname.'.1', 'r');
if(empty($sourcehandle)) {
if (empty($sourcehandle)) {
$this->error = 'Failed to open file '.$logpath.'/'.$logname.'.1';
return -4;
}
@ -769,14 +771,16 @@ class Utils
// Compress current file et recreate it
if(dol_is_file($logpath.'/'.$logname)) {
if(dol_move($logpath.'/'.$logname, $logpath.'/'.$logname.'.1', 0, 1, 0, 0)) {
if (dol_is_file($logpath.'/'.$logname)) {
if (dol_move($logpath.'/'.$logname, $logpath.'/'.$logname.'.1', 0, 1, 0, 0))
{
$newlog = fopen($logpath.'/'.$logname, 'a+');
fclose($newlog);
}
}
}
$this->output = 'Archive log files (keeping last SYSLOG_FILE_SAVES='.$nbSaves.' files) done.';
return 0;
}
}

View File

@ -82,7 +82,7 @@ class modSyslog extends DolibarrModules
// Cronjobs
$this->cronjobs = array(
0=>array('label'=>'CompressSyslogs', 'jobtype'=>'method', 'class'=>'core/class/utils.class.php', 'objectname'=>'Utils', 'method'=>'compressSyslogs', 'parameters'=>'', 'comment'=>'PurgeDeleteTemporaryFiles', 'frequency'=>1, 'unitfrequency'=> 3600 * 24, 'priority'=>50, 'status'=>0, 'test'=>true),
0=>array('label'=>'CompressSyslogs', 'jobtype'=>'method', 'class'=>'core/class/utils.class.php', 'objectname'=>'Utils', 'method'=>'compressSyslogs', 'parameters'=>'', 'comment'=>'Compress and archive log files', 'frequency'=>1, 'unitfrequency'=> 3600 * 24, 'priority'=>50, 'status'=>0, 'test'=>true),
);
}
}