summaryrefslogtreecommitdiffstats
path: root/lib/public
diff options
context:
space:
mode:
authorThomas Müller <thomas.mueller@tmit.eu>2013-10-23 07:19:14 -0700
committerThomas Müller <thomas.mueller@tmit.eu>2013-10-23 07:19:14 -0700
commit8c69a5388eeb6414d866758debaced903b468d76 (patch)
treeb53341b6b81e803d82294a8abda531e459eff0a5 /lib/public
parent959b0f912559ae0c6751cb5c0d14a9be5b58f19b (diff)
parentc4dee281e693088e445a075d5f59f54e34a1010b (diff)
downloadnextcloud-server-8c69a5388eeb6414d866758debaced903b468d76.tar.gz
nextcloud-server-8c69a5388eeb6414d866758debaced903b468d76.zip
Merge pull request #5478 from owncloud/core-logexceptionstacktrace
Expand exception stack trace in log in debug mode
Diffstat (limited to 'lib/public')
-rw-r--r--lib/public/util.php33
1 files changed, 33 insertions, 0 deletions
diff --git a/lib/public/util.php b/lib/public/util.php
index b33f07b55e6..ed0622b8d16 100644
--- a/lib/public/util.php
+++ b/lib/public/util.php
@@ -78,6 +78,39 @@ class Util {
}
/**
+ * @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
* @param string $app
* @return OC_L10N