From e570cf862136f37d6ef2ca247a636313f17a639e Mon Sep 17 00:00:00 2001 From: Olav Morken <olav.morken@uninett.no> Date: Thu, 17 Nov 2011 09:55:13 +0000 Subject: [PATCH] SimpleSAML_Logger: Fix log levels on Windows. PHP on Windows does not differentiate between all the different log levels, which means that attempting to specify the 'logging.level' option will not work properly. This patch replaces the use of the syslog constants with custom constants. Thanks to Ryan Panning for fixing this bug! git-svn-id: https://simplesamlphp.googlecode.com/svn/trunk@2981 44740490-163a-0410-bde0-09ae8108e29a --- config-templates/config.php | 12 ++++---- lib/SimpleSAML/Logger.php | 28 ++++++++++++------- .../Logger/LoggingHandlerErrorLog.php | 16 +++++------ lib/SimpleSAML/Logger/LoggingHandlerFile.php | 16 +++++------ 4 files changed, 40 insertions(+), 32 deletions(-) diff --git a/config-templates/config.php b/config-templates/config.php index 243d3d150..a4cdb0f6c 100644 --- a/config-templates/config.php +++ b/config-templates/config.php @@ -104,18 +104,18 @@ $config = array ( * Logging. * * define the minimum log level to log - * LOG_ERR No statistics, only errors - * LOG_WARNING No statistics, only warnings/errors - * LOG_NOTICE Statistics and errors - * LOG_INFO Verbose logs - * LOG_DEBUG Full debug logs - not reccomended for production + * SimpleSAML_Logger::ERR No statistics, only errors + * SimpleSAML_Logger::WARNING No statistics, only warnings/errors + * SimpleSAML_Logger::NOTICE Statistics and errors + * SimpleSAML_Logger::INFO Verbose logs + * SimpleSAML_Logger::DEBUG Full debug logs - not reccomended for production * * Choose logging handler. * * Options: [syslog,file,errorlog] * */ - 'logging.level' => LOG_NOTICE, + 'logging.level' => SimpleSAML_Logger::NOTICE, 'logging.handler' => 'syslog', /* diff --git a/lib/SimpleSAML/Logger.php b/lib/SimpleSAML/Logger.php index ea7a72777..01334f842 100644 --- a/lib/SimpleSAML/Logger.php +++ b/lib/SimpleSAML/Logger.php @@ -50,25 +50,33 @@ class SimpleSAML_Logger { * LOG_DEBUG Full debug logs - not reccomended for production */ + const EMERG = 0; + const ALERT = 1; + const CRIT = 2; + const ERR = 3; + const WARNING = 4; + const NOTICE = 5; + const INFO = 6; + const DEBUG = 7; static function emergency($string) { - self::log_internal(LOG_EMERG,$string); + self::log_internal(self::EMERG,$string); } static function critical($string) { - self::log_internal(LOG_CRIT,$string); + self::log_internal(self::CRIT,$string); } static function alert($string) { - self::log_internal(LOG_ALERT,$string); + self::log_internal(self::ALERT,$string); } static function error($string) { - self::log_internal(LOG_ERR,$string); + self::log_internal(self::ERR,$string); } static function warning($string) { - self::log_internal(LOG_WARNING,$string); + self::log_internal(self::WARNING,$string); } /** @@ -76,7 +84,7 @@ class SimpleSAML_Logger { * this level for other kind of log messages. */ static function notice($string) { - self::log_internal(LOG_NOTICE,$string); + self::log_internal(self::NOTICE,$string); } /** @@ -84,7 +92,7 @@ class SimpleSAML_Logger { * for tracing a session. */ static function info($string) { - self::log_internal(LOG_INFO,$string); + self::log_internal(self::INFO,$string); } /** @@ -92,14 +100,14 @@ class SimpleSAML_Logger { * what is neccessary for a production system. */ static function debug($string) { - self::log_internal(LOG_DEBUG,$string); + self::log_internal(self::DEBUG,$string); } /** * Statisitics */ static function stats($string) { - self::log_internal(LOG_NOTICE,$string,true); + self::log_internal(self::NOTICE,$string,true); } @@ -119,7 +127,7 @@ class SimpleSAML_Logger { /* * setting minimum log_level */ - self::$logLevel = $config->getInteger('logging.level',LOG_INFO); + self::$logLevel = $config->getInteger('logging.level',self::INFO); $handler = strtolower($handler); diff --git a/lib/SimpleSAML/Logger/LoggingHandlerErrorLog.php b/lib/SimpleSAML/Logger/LoggingHandlerErrorLog.php index 7b50c488b..0a687ee87 100644 --- a/lib/SimpleSAML/Logger/LoggingHandlerErrorLog.php +++ b/lib/SimpleSAML/Logger/LoggingHandlerErrorLog.php @@ -15,14 +15,14 @@ class SimpleSAML_Logger_LoggingHandlerErrorLog implements SimpleSAML_Logger_Logg * This array contains the mappings from syslog loglevel to names. */ private static $levelNames = array( - LOG_EMERG => 'EMERG', - LOG_ALERT => 'ALERT', - LOG_CRIT => 'CRIT', - LOG_ERR => 'ERR', - LOG_WARNING => 'WARNING', - LOG_NOTICE => 'NOTICE', - LOG_INFO => 'INFO', - LOG_DEBUG => 'DEBUG', + SimpleSAML_Logger::EMERG => 'EMERG', + SimpleSAML_Logger::ALERT => 'ALERT', + SimpleSAML_Logger::CRIT => 'CRIT', + SimpleSAML_Logger::ERR => 'ERR', + SimpleSAML_Logger::WARNING => 'WARNING', + SimpleSAML_Logger::NOTICE => 'NOTICE', + SimpleSAML_Logger::INFO => 'INFO', + SimpleSAML_Logger::DEBUG => 'DEBUG', ); diff --git a/lib/SimpleSAML/Logger/LoggingHandlerFile.php b/lib/SimpleSAML/Logger/LoggingHandlerFile.php index 4cc70f428..43ed5fb16 100644 --- a/lib/SimpleSAML/Logger/LoggingHandlerFile.php +++ b/lib/SimpleSAML/Logger/LoggingHandlerFile.php @@ -16,14 +16,14 @@ class SimpleSAML_Logger_LoggingHandlerFile implements SimpleSAML_Logger_LoggingH * more or less directly from SimpleSAML_Logger_LoggingHandlerErrorLog. */ private static $levelNames = array( - LOG_EMERG => 'EMERGENCY', - LOG_ALERT => 'ALERT', - LOG_CRIT => 'CRITICAL', - LOG_ERR => 'ERROR', - LOG_WARNING => 'WARNING', - LOG_NOTICE => 'NOTICE', - LOG_INFO => 'INFO', - LOG_DEBUG => 'DEBUG', + SimpleSAML_Logger::EMERG => 'EMERGENCY', + SimpleSAML_Logger::ALERT => 'ALERT', + SimpleSAML_Logger::CRIT => 'CRITICAL', + SimpleSAML_Logger::ERR => 'ERROR', + SimpleSAML_Logger::WARNING => 'WARNING', + SimpleSAML_Logger::NOTICE => 'NOTICE', + SimpleSAML_Logger::INFO => 'INFO', + SimpleSAML_Logger::DEBUG => 'DEBUG', ); private $logFile = null; -- GitLab