From 7bbbda2dcef7f8f704390fa8cadc81d7193a9643 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur <eldy@destailleur.fr> Date: Thu, 28 Feb 2013 16:19:16 +0100 Subject: [PATCH] New: dol_syslog method accept a suffix to use different log files for log. --- ChangeLog | 3 ++- htdocs/core/lib/functions.lib.php | 17 +++++++++-------- htdocs/core/modules/syslog/mod_syslog_file.php | 15 +++++++++------ 3 files changed, 20 insertions(+), 15 deletions(-) diff --git a/ChangeLog b/ChangeLog index 9509d17c800..811660a00b0 100644 --- a/ChangeLog +++ b/ChangeLog @@ -31,7 +31,8 @@ For developers: - Function plimit of databases drivers accept -1 as value (it means default value set into conf->liste_limit). - New: Add option dol_hide_topmenu and dol_hide_leftmenu onto login page. - +- New: dol_syslog method accept a suffix to use different log files for log. + For translators: - Update language files. diff --git a/htdocs/core/lib/functions.lib.php b/htdocs/core/lib/functions.lib.php index 36cf943c51b..99df1e73053 100644 --- a/htdocs/core/lib/functions.lib.php +++ b/htdocs/core/lib/functions.lib.php @@ -485,15 +485,16 @@ function dol_strtoupper($utf8_string) * This function works only if syslog module is enabled. * This must not use any call to other function calling dol_syslog (avoid infinite loop). * - * @param string $message Line to log. Ne doit pas etre traduit si level = LOG_ERR - * @param int $level Log level - * 0=Show nothing - * On Windows LOG_ERR=4, LOG_WARNING=5, LOG_NOTICE=LOG_INFO=6, LOG_DEBUG=6 si define_syslog_variables ou PHP 5.3+, 7 si dolibarr - * On Linux LOG_ERR=3, LOG_WARNING=4, LOG_INFO=6, LOG_DEBUG=7 - * @param int $ident 1=Increase ident of 1, -1=Decrease ident of 1 + * @param string $message Line to log. Ne doit pas etre traduit si level = LOG_ERR + * @param int $level Log level + * 0=Show nothing + * On Windows LOG_ERR=4, LOG_WARNING=5, LOG_NOTICE=LOG_INFO=6, LOG_DEBUG=6 si define_syslog_variables ou PHP 5.3+, 7 si dolibarr + * On Linux LOG_ERR=3, LOG_WARNING=4, LOG_INFO=6, LOG_DEBUG=7 + * @param int $ident 1=Increase ident of 1, -1=Decrease ident of 1 + * @param string $suffixinfilename When output is a file, append this suffix into default log filename. * @return void */ -function dol_syslog($message, $level = LOG_INFO, $ident = 0) +function dol_syslog($message, $level = LOG_INFO, $ident = 0, $suffixinfilename='') { global $conf, $user; @@ -543,7 +544,7 @@ function dol_syslog($message, $level = LOG_INFO, $ident = 0) // Loop on each log handler and send output foreach ($conf->loghandlers as $loghandlerinstance) { - $loghandlerinstance->export($data); + $loghandlerinstance->export($data,$suffixinfilename); } unset($data); } diff --git a/htdocs/core/modules/syslog/mod_syslog_file.php b/htdocs/core/modules/syslog/mod_syslog_file.php index b0e1bd550b4..f5315f064ae 100644 --- a/htdocs/core/modules/syslog/mod_syslog_file.php +++ b/htdocs/core/modules/syslog/mod_syslog_file.php @@ -96,22 +96,25 @@ class mod_syslog_file extends LogHandler implements LogHandlerInterface /** * Return the parsed logfile path * - * @return string + * @param string $suffixinfilename When output is a file, append this suffix into default log filename. + * @return string */ - private function getFilename() + private function getFilename($suffixinfilename='') { - return str_replace('DOL_DATA_ROOT', DOL_DATA_ROOT, SYSLOG_FILE); + $tmp=str_replace('DOL_DATA_ROOT', DOL_DATA_ROOT, SYSLOG_FILE); + return $suffixinfilename?preg_replace('/\.log$/i', $suffixinfilename.'.log', $tmp):$tmp; } /** * Export the message * - * @param array $content Array containing the info about the message + * @param array $content Array containing the info about the message + * @param string $suffixinfilename When output is a file, append this suffix into default log filename. * @return void */ - public function export($content) + public function export($content, $suffixinfilename='') { - $logfile = $this->getFilename(); + $logfile = $this->getFilename($suffixinfilename); if (defined("SYSLOG_FILE_NO_ERROR")) $filefd = @fopen($logfile, 'a+'); else $filefd = fopen($logfile, 'a+'); -- GitLab