3require_once DOL_DOCUMENT_ROOT.
'/core/modules/syslog/logHandler.php';
10 public $code =
'file';
22 return $langs->trans(
'File');
44 return $langs->trans(
'YouCanUseDOL_DATA_ROOT');
55 return empty($conf->global->SYSLOG_DISABLE_LOGHANDLER_FILE) ? 1 : 0;
69 'name' => $langs->trans(
'SyslogFilename'),
70 'constant' =>
'SYSLOG_FILE',
71 'default' =>
'DOL_DATA_ROOT/dolibarr.log',
90 if (file_exists($filename) && is_writable($filename)) {
93 $errors[] = $langs->trans(
"ErrorFailedToOpenFile", $filename);
109 if (empty($conf->global->SYSLOG_FILE)) {
110 $tmp = DOL_DATA_ROOT.
'/dolibarr.log';
112 $tmp = str_replace(
'DOL_DATA_ROOT', DOL_DATA_ROOT, $conf->global->SYSLOG_FILE);
115 if (!empty($conf->global->SYSLOG_FILE_ONEPERSESSION)) {
116 if (is_numeric($conf->global->SYSLOG_FILE_ONEPERSESSION)) {
117 if ($conf->global->SYSLOG_FILE_ONEPERSESSION == 1) {
118 $suffixinfilename .=
'_'.session_name();
120 if ($conf->global->SYSLOG_FILE_ONEPERSESSION == 2) {
121 $suffixinfilename .=
'_'.session_name().
'_'.$_SERVER[
"REMOTE_ADDR"];
124 $suffixinfilename .=
'_'.$conf->global->SYSLOG_FILE_ONEPERSESSION;
128 return $suffixinfilename ? preg_replace(
'/\.log$/i', $suffixinfilename.
'.log', $tmp) : $tmp;
138 public function export($content, $suffixinfilename =
'')
140 global $conf, $dolibarr_main_prod;
142 if (!empty($conf->global->MAIN_SYSLOG_DISABLE_FILE)) {
149 if (defined(
'SYSLOG_FILE_NO_ERROR')) {
150 $filefd = @fopen($logfile,
'a+');
152 $filefd = fopen($logfile,
'a+');
156 if (!defined(
'SYSLOG_FILE_NO_ERROR') || !constant(
'SYSLOG_FILE_NO_ERROR')) {
159 print
'Failed to open log file '.($dolibarr_main_prod ?basename($logfile) : $logfile);
163 LOG_EMERG =>
'EMERG',
164 LOG_ALERT =>
'ALERT',
167 LOG_WARNING =>
'WARNING',
168 LOG_NOTICE =>
'NOTICE',
174 if (!empty($conf->global->MAIN_SYSLOG_SHOW_DELAY)) {
175 $now = microtime(
true);
176 $delay =
" ".sprintf(
"%05.3f", $this->lastTime != 0 ? $now - $this->lastTime : 0);
177 $this->lastTime = $now;
180 $message =
dol_print_date(
dol_now(
'gmt'),
'standard',
'gmt').$delay.
" ".sprintf(
"%-7s", $logLevels[$content[
'level']]).
" ".sprintf(
"%-15s", $content[
'ip']).
" ".($this->ident > 0 ?str_pad(
'', $this->ident,
' ') :
'').$content[
'message'];
181 fwrite($filefd, $message.
"\n");
Parent class for log handlers.
Class to manage logging to a file.
isActive()
Is the module active ?
getInfo()
Content of the info tooltip.
getName()
Return name of logger.
getVersion()
Version of the module ('x.y.z' or 'dolibarr' or 'experimental' or 'development')
checkConfiguration()
Return if configuration is valid.
export($content, $suffixinfilename='')
Export the message.
getFilename($suffixinfilename='')
Return the parsed logfile path.
configure()
Return array of configuration data.
dol_print_date($time, $format='', $tzoutput='auto', $outputlangs='', $encodetooutput=false)
Output date in a string format according to outputlangs (or langs if not defined).
dolChmod($filepath, $newmask='')
Change mod of a file.
dol_now($mode='auto')
Return date for now.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.