Skip to content
Snippets Groups Projects
Commit 7506eb3b authored by Olav Morken's avatar Olav Morken
Browse files

Add support for masking error messages.

git-svn-id: https://simplesamlphp.googlecode.com/svn/trunk@1857 44740490-163a-0410-bde0-09ae8108e29a
parent 585edcac
No related branches found
No related tags found
No related merge requests found
......@@ -9,6 +9,25 @@
*/
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
*/
public static $logMask = 0;
/**
* Will return sp.example.org
......@@ -2062,6 +2081,38 @@ class SimpleSAML_Utilities {
return $tempDir;
}
/**
* Disable reporting of 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];
}
}
?>
\ No newline at end of file
......@@ -32,6 +32,11 @@ set_exception_handler('SimpleSAML_exception_handler');
/* Log full backtrace on errors and warnings. */
function SimpleSAML_error_handler($errno, $errstr, $errfile = NULL, $errline = 0, $errcontext = NULL) {
if ($errno & SimpleSAML_Utilities::$logMask) {
/* Masked error. */
return FALSE;
}
static $limit = 5;
$limit -= 1;
if ($limit < 0) {
......
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