From a68effe4e7035b5b321749297c653c4c0751b2cd Mon Sep 17 00:00:00 2001 From: Daniel Reichelt Date: Tue, 16 Feb 2016 20:19:22 +0100 Subject: [PATCH] logging: add loglevel to syslog output --- lib/classes/logger/class.FroxlorLogger.php | 27 +----------- lib/classes/logger/class.SysLogger.php | 4 +- .../logger/function.getLogLevelDesc.php | 44 +++++++++++++++++++ 3 files changed, 48 insertions(+), 27 deletions(-) create mode 100644 lib/functions/logger/function.getLogLevelDesc.php diff --git a/lib/classes/logger/class.FroxlorLogger.php b/lib/classes/logger/class.FroxlorLogger.php index 546676c4..768bcf00 100644 --- a/lib/classes/logger/class.FroxlorLogger.php +++ b/lib/classes/logger/class.FroxlorLogger.php @@ -104,31 +104,8 @@ class FroxlorLogger { return; } - switch($type) { - case LOG_INFO: - $_type = 'information'; - break; - case LOG_NOTICE: - $_type = 'notice'; - break; - case LOG_WARNING: - $_type = 'warning'; - break; - case LOG_ERR: - $_type = 'error'; - break; - case LOG_CRIT: - $_type = 'critical'; - break; - case LOG_DEBUG: - $_type = 'debug'; - break; - default: - $_type = 'unknown'; - break; - } - if (self::$crondebug_flag || $type <= LOG_WARNING) { # more severe levels have smaller numbers - echo "[".$_type."] ".$text.PHP_EOL; + if (self::$crondebug_flag || $type <= LOG_WARNING) { // more severe levels have smaller numbers + echo "[".getLogLevelDesc($type)."] ".$text.PHP_EOL; } if (Settings::Get('logger.log_cron') == '0' diff --git a/lib/classes/logger/class.SysLogger.php b/lib/classes/logger/class.SysLogger.php index e1b941ad..f15396e2 100644 --- a/lib/classes/logger/class.SysLogger.php +++ b/lib/classes/logger/class.SysLogger.php @@ -114,9 +114,9 @@ class SysLogger extends AbstractLogger { if ($text != null && $text != '' ) { - syslog((int)$type, "[" . ucfirst($_action) . " Action " . $name . "] " . $text); + syslog((int)$type, "[" . ucfirst($_action) . " Action " . $name . "] [".getLogLevelDesc($type)."] " . $text); } else { - syslog((int)$type, "[" . ucfirst($_action) . " Action " . $name . "] No text given!!! Check scripts!"); + syslog((int)$type, "[" . ucfirst($_action) . " Action " . $name . "] [".getLogLevelDesc($type)."] No text given!!! Check scripts!"); } closelog(); diff --git a/lib/functions/logger/function.getLogLevelDesc.php b/lib/functions/logger/function.getLogLevelDesc.php new file mode 100644 index 00000000..0eff7ad7 --- /dev/null +++ b/lib/functions/logger/function.getLogLevelDesc.php @@ -0,0 +1,44 @@ + + * @author Daniel Reichelt (2016-) + * @license GPLv2 http://files.froxlor.org/misc/COPYING.txt + * @package Functions + * + */ + +function getLogLevelDesc($type) { + switch($type) { + case LOG_INFO: + $_type = 'information'; + break; + case LOG_NOTICE: + $_type = 'notice'; + break; + case LOG_WARNING: + $_type = 'warning'; + break; + case LOG_ERR: + $_type = 'error'; + break; + case LOG_CRIT: + $_type = 'critical'; + break; + case LOG_DEBUG: + $_type = 'debug'; + break; + default: + $_type = 'unknown'; + break; + } + return $_type; +}