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

Error_Exception: Add functions to write the exception to the logs.

This patch adds several functions for writing the exception
to the logs with a full backtrace, including the causes for the exception.

git-svn-id: https://simplesamlphp.googlecode.com/svn/trunk@1566 44740490-163a-0410-bde0-09ae8108e29a
parent e8bc5cb4
No related branches found
No related tags found
No related merge requests found
...@@ -92,6 +92,96 @@ class SimpleSAML_Error_Exception extends Exception { ...@@ -92,6 +92,96 @@ class SimpleSAML_Error_Exception extends Exception {
} }
/**
* Format this exception for logging.
*
* Create an array with lines for logging.
*
* @return array Log lines which should be written out.
*/
public function format() {
$ret = array();
$e = $this;
do {
$err = get_class($e) . ': ' . $e->getMessage();
if ($e === $this) {
$ret[] = $err;
} else {
$ret[] = 'Caused by: ' . $err;
}
$ret[] = 'Backtrace:';
$depth = count($e->backtrace);
foreach ($e->backtrace as $i => $trace) {
$ret[] = ($depth - $i - 1) . ' ' . $trace;
}
$e = $e->cause;
} while ($e !== NULL);
return $ret;
}
/**
* Print the exception to the log with log level error.
*
* This function will write this exception to the log, including a full backtrace.
*/
public function logError() {
$lines = $this->format();
foreach ($lines as $line) {
SimpleSAML_Logger::error($line);
}
}
/**
* Print the exception to the log with log level warning.
*
* This function will write this exception to the log, including a full backtrace.
*/
public function logWarning() {
$lines = $this->format();
foreach ($lines as $line) {
SimpleSAML_Logger::warning($line);
}
}
/**
* Print the exception to the log with log level info.
*
* This function will write this exception to the log, including a full backtrace.
*/
public function logInfo() {
$lines = $this->format();
foreach ($lines as $line) {
SimpleSAML_Logger::debug($line);
}
}
/**
* Print the exception to the log with log level debug.
*
* This function will write this exception to the log, including a full backtrace.
*/
public function logDebug() {
$lines = $this->format();
foreach ($lines as $line) {
SimpleSAML_Logger::debug($line);
}
}
/** /**
* Function for serialization. * Function for serialization.
* *
......
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