diff --git a/htdocs/core/modules/syslog/mod_syslog_file.php b/htdocs/core/modules/syslog/mod_syslog_file.php index 4fd8452f970..b00fa11945a 100644 --- a/htdocs/core/modules/syslog/mod_syslog_file.php +++ b/htdocs/core/modules/syslog/mod_syslog_file.php @@ -116,27 +116,32 @@ class mod_syslog_file extends LogHandler implements LogHandlerInterface if (defined("SYSLOG_FILE_NO_ERROR")) $filefd = @fopen($logfile, 'a+'); else $filefd = fopen($logfile, 'a+'); - if (!$filefd && ! defined("SYSLOG_FILE_NO_ERROR")) + if (! $filefd) { - // Do not break dolibarr usage if log fails - //throw new Exception('Failed to open log file '.basename($logfile)); - print 'Failed to open log file '.basename($logfile); + if (! defined("SYSLOG_FILE_NO_ERROR")) + { + // Do not break dolibarr usage if log fails + //throw new Exception('Failed to open log file '.basename($logfile)); + print 'Failed to open log file '.basename($logfile); + } } + else + { + $logLevels = array( + LOG_EMERG => 'EMERG', + LOG_ALERT => 'ALERT', + LOG_CRIT => 'CRIT', + LOG_ERR => 'ERR', + LOG_WARNING => 'WARNING', + LOG_NOTICE => 'NOTICE', + LOG_INFO => 'INFO', + LOG_DEBUG => 'DEBUG' + ); - $logLevels = array( - LOG_EMERG => 'EMERG', - LOG_ALERT => 'ALERT', - LOG_CRIT => 'CRIT', - LOG_ERR => 'ERR', - LOG_WARNING => 'WARNING', - LOG_NOTICE => 'NOTICE', - LOG_INFO => 'INFO', - LOG_DEBUG => 'DEBUG' - ); + $message = dol_print_date(time(),"%Y-%m-%d %H:%M:%S")." ".sprintf("%-5s", $logLevels[$content['level']])." ".sprintf("%-15s", $content['ip'])." ".($this->ident>0?str_pad('',$this->ident,' '):'').$content['message']; - $message = dol_print_date(time(),"%Y-%m-%d %H:%M:%S")." ".sprintf("%-5s", $logLevels[$content['level']])." ".sprintf("%-15s", $content['ip'])." ".($this->ident>0?str_pad('',$this->ident,' '):'').$content['message']; - - fwrite($filefd, $message."\n"); - fclose($filefd); + fwrite($filefd, $message."\n"); + fclose($filefd); + } } } \ No newline at end of file