6require_once DOL_DOCUMENT_ROOT.
'/core/modules/syslog/logHandler.php';
16 public $code =
'file';
31 return $langs->trans(
'File');
53 return $langs->trans(
'YouCanUseDOL_DATA_ROOT');
77 'name' => $langs->trans(
'SyslogFilename'),
78 'constant' =>
'SYSLOG_FILE',
79 'default' =>
'DOL_DATA_ROOT/dolibarr.log',
80 'css' =>
'minwidth300 maxwidth500'
96 if (file_exists($filename) && is_writable($filename)) {
100 $this->errors[] = $langs->trans(
"ErrorFailedToOpenFile", $filename);
116 $tmp = DOL_DATA_ROOT.
'/dolibarr.log';
118 $tmp = str_replace(
'DOL_DATA_ROOT', DOL_DATA_ROOT, $conf->global->SYSLOG_FILE);
125 $suffixinfilename .=
'_'.session_name();
135 if (defined(
'SYSLOG_FILE_ADDSUFFIX')) {
136 $suffixinfilename .=
'_' . constant(
'SYSLOG_FILE_ADDSUFFIX');
138 if (defined(
'SYSLOG_FILE_ADDIP')) {
139 $suffixinfilename .=
'_'.getUserRemoteIP();
142 return $suffixinfilename ? preg_replace(
'/\.log$/i', $suffixinfilename.
'.log', $tmp) : $tmp;
147 const DOL_LOG_LEVELS = array(
148 LOG_EMERG =>
'EMERG',
149 LOG_ALERT =>
'ALERT',
152 LOG_WARNING =>
'WARNING',
153 LOG_NOTICE =>
'NOTICE',
166 public function export($content, $suffixinfilename =
'')
177 $now = microtime(
true);
178 $delay =
" ".sprintf(
"%05.3f", $this->lastTime != 0 ? $now - $this->lastTime : 0);
179 $this->lastTime = $now;
181 $message =
dol_print_date(
dol_now(
'gmt'),
'standard',
'gmt').$delay.
" ".sprintf(
"%-7s", self::DOL_LOG_LEVELS[$content[
'level']]).
" ".sprintf(
"%-15s", $content[
'ip']);
182 $message .=
" ".sprintf(
"%7s",
dol_trunc($content[
'ospid'], 7,
'right',
'UTF-8', 1));
183 $message .=
" ".sprintf(
"%6s",
dol_trunc($content[
'osuser'], 6,
'right',
'UTF-8', 1));
185 $message .=
" ".($this->ident > 0 ? str_pad(
'', ((
int) $this->ident),
' ') :
'').$content[
'message'];
194 if (defined(
'SYSLOG_FILE_NO_ERROR')) {
195 $filefd = @fopen($logfile,
"a");
197 $filefd = fopen($logfile,
"a");
200 if ($filefd !==
false) {
201 $result = fwrite($filefd, $message);
205 if ($result ===
false && (!defined(
'SYSLOG_FILE_NO_ERROR') || !constant(
'SYSLOG_FILE_NO_ERROR'))) {
206 global $dolibarr_main_prod;
209 print
'Failed to write to log file '.($dolibarr_main_prod ? basename($logfile) : $logfile);
Parent class for log handlers.
Class to manage logging to a file.
isActive()
Is the logger 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.
dolChmod($filepath, $newmask='')
Change mod of a file.
dol_now($mode='auto')
Return date for now.
getDolGlobalInt($key, $default=0)
Return a Dolibarr global constant int value.
dol_print_date($time, $format='', $tzoutput='auto', $outputlangs=null, $encodetooutput=false)
Output date in a string format according to outputlangs (or langs if not defined).
dol_trunc($string, $size=40, $trunc='right', $stringencoding='UTF-8', $nodot=0, $display=0)
Truncate a string to a particular length adding '…' if string larger than length.
getDolGlobalString($key, $default='')
Return a Dolibarr global constant string value.
getUserRemoteIP()
Return the IP of remote user.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.