diff --git a/lib/SimpleSAML/Logger.php b/lib/SimpleSAML/Logger.php index 11d275dd696cec46e82bbe22da06fff7ac8cd6e5..f505a4339c2bd7a595d3365b0be0efe60eef72dd 100644 --- a/lib/SimpleSAML/Logger.php +++ b/lib/SimpleSAML/Logger.php @@ -40,6 +40,24 @@ class SimpleSAML_Logger */ private static $earlyLog = array(); + /** + * List of log levels. + * + * This list is used to restore the log levels after some log levels have been disabled. + * + * @var array + */ + private static $logLevelStack = array(); + + /** + * The current mask of log levels disabled. + * + * Note: this mask is not directly related to the PHP error reporting level. + * + * @var int + */ + private static $logMask = 0; + /** * This constant defines the string we set the track ID to while we are fetching the track ID from the session @@ -256,6 +274,51 @@ class SimpleSAML_Logger } + /** + * Evaluate whether errors of a certain error level are masked or not. + * + * @param int $errno The level of the error to check. + * @return bool True if the error is masked, false otherwise. + */ + public static function isErrorMasked($errno) + { + return ($errno & self::$logMask) || !($errno & error_reporting()); + } + + + /** + * Disable error reporting for the given log levels. + * + * Every call to this function must be followed by a call to popErrorMask(). + * + * @param int $mask The log levels that should be masked. + */ + public static function maskErrors($mask) + { + assert('is_int($mask)'); + + $currentEnabled = error_reporting(); + self::$logLevelStack[] = array($currentEnabled, self::$logMask); + + $currentEnabled &= ~$mask; + error_reporting($currentEnabled); + self::$logMask |= $mask; + } + + + /** + * Pop an error mask. + * + * This function restores the previous error mask. + */ + public static function popErrorMask() + { + $lastMask = array_pop(self::$logLevelStack); + error_reporting($lastMask[0]); + self::$logMask = $lastMask[1]; + } + + /** * Defer a message for later logging. * diff --git a/lib/SimpleSAML/Utilities.php b/lib/SimpleSAML/Utilities.php index 0aea5f28475dd1551f7c8b33a746f45767f6cedf..d0e33ee4ab43b819717eebac30ce315c13b3c54b 100644 --- a/lib/SimpleSAML/Utilities.php +++ b/lib/SimpleSAML/Utilities.php @@ -13,21 +13,7 @@ class SimpleSAML_Utilities { /** - * List of log levels. - * - * This list is used to restore the log levels after some log levels are disabled. - * - * @var array - */ - private static $logLevelStack = array(); - - - /** - * The current mask of disabled log levels. - * - * Note: This mask is not directly related to the PHP error reporting level. - * - * @var int + * @deprecated This property will be removed in SSP 2.0. Please use SimpleSAML_Logger::isErrorMasked() instead. */ public static $logMask = 0; @@ -629,29 +615,20 @@ class SimpleSAML_Utilities /** - * @deprecated This method will be removed in SSP 2.0. + * @deprecated This method will be removed in SSP 2.0. Please use SimpleSAML_Logger::maskErrors() instead. */ public static function maskErrors($mask) { - assert('is_int($mask)'); - - $currentEnabled = error_reporting(); - self::$logLevelStack[] = array($currentEnabled, self::$logMask); - - $currentEnabled &= ~$mask; - error_reporting($currentEnabled); - self::$logMask |= $mask; + SimpleSAML_Logger::maskErrors($mask); } /** - * @deprecated This method will be removed in SSP 2.0. + * @deprecated This method will be removed in SSP 2.0. Please use SimpleSAML_Logger::popErrorMask() instead. */ public static function popErrorMask() { - $lastMask = array_pop(self::$logLevelStack); - error_reporting($lastMask[0]); - self::$logMask = $lastMask[1]; + SimpleSAML_Logger::popErrorMask(); } @@ -727,5 +704,4 @@ class SimpleSAML_Utilities { \SimpleSAML\Utils\HTTP::setCookie($name, $value, $params, $throw); } - } diff --git a/www/_include.php b/www/_include.php index 5c25adeeafe80440053a8d0a61947a969e7bf6a8..875559d1d0cca2220ec4ee545600d94aee2061c4 100644 --- a/www/_include.php +++ b/www/_include.php @@ -59,7 +59,7 @@ function SimpleSAML_error_handler($errno, $errstr, $errfile = null, $errline = 0 return false; } - if ($errno & SimpleSAML_Utilities::$logMask || !($errno & error_reporting())) { + if (SimpleSAML_Logger::isErrorMasked($errno)) { // masked error return false; }