Merge pull request #5478 from owncloud/core-logexceptionstacktrace
Expand exception stack trace in log in debug mode
This commit is contained in:
commit
8c69a5388e
|
@ -30,8 +30,9 @@ try {
|
||||||
OC::handleRequest();
|
OC::handleRequest();
|
||||||
|
|
||||||
} catch (Exception $ex) {
|
} catch (Exception $ex) {
|
||||||
|
\OCP\Util::logException('index', $ex);
|
||||||
|
|
||||||
//show the user a detailed error page
|
//show the user a detailed error page
|
||||||
\OCP\Util::writeLog('index', $ex->getMessage(), \OCP\Util::FATAL);
|
|
||||||
OC_Response::setStatus(OC_Response::STATUS_INTERNAL_SERVER_ERROR);
|
OC_Response::setStatus(OC_Response::STATUS_INTERNAL_SERVER_ERROR);
|
||||||
OC_Template::printExceptionErrorPage($ex);
|
OC_Template::printExceptionErrorPage($ex);
|
||||||
}
|
}
|
||||||
|
|
|
@ -77,6 +77,39 @@ class Util {
|
||||||
\OC_LOG::write( $app, $message, $level );
|
\OC_LOG::write( $app, $message, $level );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief write exception into the log. Include the stack trace
|
||||||
|
* if DEBUG mode is enabled
|
||||||
|
* @param Exception $ex exception to log
|
||||||
|
*/
|
||||||
|
public static function logException( $app, \Exception $ex ) {
|
||||||
|
$message = $ex->getMessage();
|
||||||
|
if ($ex->getCode()) {
|
||||||
|
$message .= ' [' . $ex->getCode() . ']';
|
||||||
|
}
|
||||||
|
\OCP\Util::writeLog($app, 'Exception: ' . $message, \OCP\Util::FATAL);
|
||||||
|
if (defined('DEBUG') and DEBUG) {
|
||||||
|
// also log stack trace
|
||||||
|
$stack = explode('#', $ex->getTraceAsString());
|
||||||
|
// first element is empty
|
||||||
|
array_shift($stack);
|
||||||
|
foreach ($stack as $s) {
|
||||||
|
\OCP\Util::writeLog($app, 'Exception: ' . $s, \OCP\Util::FATAL);
|
||||||
|
}
|
||||||
|
|
||||||
|
// include cause
|
||||||
|
$l = \OC_L10N::get('lib');
|
||||||
|
while (method_exists($ex, 'getPrevious') && $ex = $ex->getPrevious()) {
|
||||||
|
$message .= ' - '.$l->t('Caused by:').' ';
|
||||||
|
$message .= $ex->getMessage();
|
||||||
|
if ($ex->getCode()) {
|
||||||
|
$message .= '[' . $ex->getCode() . '] ';
|
||||||
|
}
|
||||||
|
\OCP\Util::writeLog($app, 'Exception: ' . $message, \OCP\Util::FATAL);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief get l10n object
|
* @brief get l10n object
|
||||||
* @param string $app
|
* @param string $app
|
||||||
|
|
Loading…
Reference in New Issue