Skip to content
Snippets Groups Projects
Commit 0858c10c authored by Jaime Pérez's avatar Jaime Pérez
Browse files

Log backtraces with the same log level as the error messages, whatever that is.

It's not very useful to log backtraces always as debug, since that implies getting all the log messages, while backtraces would still help debug a particular error.
parent c08ee897
No related branches found
No related tags found
No related merge requests found
......@@ -196,15 +196,25 @@ class SimpleSAML_Error_Exception extends Exception
/**
* Print the backtrace to the log if the 'debug' option is enabled in the configuration.
*/
protected function logBacktrace()
protected function logBacktrace($level = \SimpleSAML\Logger::DEBUG)
{
if (!SimpleSAML_Configuration::getInstance()->getBoolean('debug', false)) {
return;
}
$backtrace = $this->formatBacktrace();
$callback = array('\SimpleSAML\Logger');
$functions = array(
\SimpleSAML\Logger::ERR => 'error',
\SimpleSAML\Logger::WARNING => 'warning',
\SimpleSAML\Logger::INFO => 'info',
\SimpleSAML\Logger::DEBUG => 'debug',
);
$callback[] = $functions[$level];
foreach ($backtrace as $line) {
SimpleSAML\Logger::debug($line);
call_user_func($callback, $line);
}
}
......@@ -224,7 +234,7 @@ class SimpleSAML_Error_Exception extends Exception
SimpleSAML\Logger::INFO => 'logInfo',
SimpleSAML\Logger::DEBUG => 'logDebug',
);
call_user_func(array($this, $fn[$default_level]));
call_user_func(array($this, $fn[$default_level]), $default_level);
}
......@@ -236,7 +246,7 @@ class SimpleSAML_Error_Exception extends Exception
public function logError()
{
SimpleSAML\Logger::error($this->getClass().': '.$this->getMessage());
$this->logBacktrace();
$this->logBacktrace(\SimpleSAML\Logger::ERR);
}
......@@ -248,7 +258,7 @@ class SimpleSAML_Error_Exception extends Exception
public function logWarning()
{
SimpleSAML\Logger::warning($this->getClass().': '.$this->getMessage());
$this->logBacktrace();
$this->logBacktrace(\SimpleSAML\Logger::WARNING);
}
......@@ -260,7 +270,7 @@ class SimpleSAML_Error_Exception extends Exception
public function logInfo()
{
SimpleSAML\Logger::info($this->getClass().': '.$this->getMessage());
$this->logBacktrace();
$this->logBacktrace(\SimpleSAML\Logger::INFO);
}
......@@ -272,7 +282,7 @@ class SimpleSAML_Error_Exception extends Exception
public function logDebug()
{
SimpleSAML\Logger::debug($this->getClass().': '.$this->getMessage());
$this->logBacktrace();
$this->logBacktrace(\SimpleSAML\Logger::DEBUG);
}
......
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