Skip to content
Snippets Groups Projects
Commit f00b5f63 authored by Jaime Perez Crespo's avatar Jaime Perez Crespo
Browse files

Move the error-reporting logic in SimpleSAML_Utilities to the...

Move the error-reporting logic in SimpleSAML_Utilities to the SimpleSAML_Logger class, and add a new method there to evaluate whether an error would be masked or not according to its level.
parent 9cfdded3
No related branches found
No related tags found
No related merge requests found
......@@ -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.
*
......
......@@ -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);
}
}
......@@ -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;
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment