9require_once DOL_DOCUMENT_ROOT.
'/core/modules/syslog/logHandler.php';
17 const DOL_LOG_LEVELS = array(
22 LOG_WARNING =>
'WARNING',
23 LOG_NOTICE =>
'NOTICE',
31 public $code =
'file';
46 return $langs->trans(
'File');
68 return $langs->trans(
'YouCanUseDOL_DATA_ROOT');
92 'name' => $langs->trans(
'SyslogFilename'),
93 'constant' =>
'SYSLOG_FILE',
94 'default' =>
'DOL_DATA_ROOT/dolibarr.log',
95 'css' =>
'minwidth300 maxwidth500'
111 if (file_exists($filename) && is_writable($filename)) {
115 $this->errors[] = $langs->trans(
"ErrorFailedToOpenFile", $filename);
131 $tmp = DOL_DATA_ROOT.
'/dolibarr.log';
133 $tmp = str_replace(
'DOL_DATA_ROOT', DOL_DATA_ROOT,
$conf->global->SYSLOG_FILE);
140 $suffixinfilename .=
'_'.session_name();
150 if (defined(
'SYSLOG_FILE_ADDSUFFIX')) {
151 $suffixinfilename .=
'_' . constant(
'SYSLOG_FILE_ADDSUFFIX');
153 if (defined(
'SYSLOG_FILE_ADDIP')) {
154 $suffixinfilename .=
'_'.getUserRemoteIP();
157 return $suffixinfilename ? preg_replace(
'/\.log$/i', $suffixinfilename.
'.log', $tmp) : $tmp;
167 public function export($content, $suffixinfilename =
'')
178 $now = microtime(
true);
179 $delay =
" ".sprintf(
"%05.3f", $this->lastTime != 0 ? $now - $this->lastTime : 0);
180 $this->lastTime = $now;
182 $message =
dol_print_date(
dol_now(
'gmt'),
'standard',
'gmt').$delay.
" ".sprintf(
"%-7s", self::DOL_LOG_LEVELS[$content[
'level']]).
" ".sprintf(
"%-15s", $content[
'ip']);
183 $message .=
" ".sprintf(
"%7s",
dol_trunc($content[
'ospid'], 7,
'right',
'UTF-8', 1));
184 $message .=
" ".sprintf(
"%6s",
dol_trunc($content[
'osuser'], 6,
'right',
'UTF-8', 1));
186 $message .=
" ".($this->ident > 0 ? str_pad(
'', ((
int) $this->ident),
' ') :
'').$content[
'message'];
195 if (defined(
'SYSLOG_FILE_NO_ERROR') || !empty($suffixinfilename)) {
196 $filefd = @fopen($logfile,
"a");
198 $filefd = fopen($logfile,
"a");
201 if ($filefd !==
false) {
202 $result = fwrite($filefd, $message);
206 if ($result ===
false && empty($suffixinfilename) && (!defined(
'SYSLOG_FILE_NO_ERROR') || !constant(
'SYSLOG_FILE_NO_ERROR'))) {
207 global $dolibarr_main_prod;
210 print
'Failed to write to log file '.($dolibarr_main_prod ? basename($logfile) : $logfile).
"\n";
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.
dol_now($mode='gmt')
Return date for now.
dolChmod($filepath, $newmask='')
Change mod of a file.
getDolGlobalInt($key, $default=0)
Return a Dolibarr global constant int value.
dol_print_date($time, $format='', $tzoutput='auto', $outputlangs=null, $encodetooutput=false, $decorate=0)
Output date in a string format according to outputlangs (or langs if not defined).
getUserRemoteIP($trusted=0)
Return the real IP of remote user.
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.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.