]> source.dussan.org Git - nextcloud-server.git/commitdiff
Expand exception stack trace in log in debug mode
authorVincent Petry <pvince81@owncloud.com>
Tue, 22 Oct 2013 17:16:34 +0000 (19:16 +0200)
committerVincent Petry <pvince81@owncloud.com>
Tue, 22 Oct 2013 17:17:41 +0000 (19:17 +0200)
index.php

index 40063fa6e05b44305807b88926d331e6477b5bba..1b9b4a58f7f9fdbfbbe316f223437db328f93d86 100755 (executable)
--- a/index.php
+++ b/index.php
 
 $RUNTIME_NOAPPS = true; //no apps, yet
 
+function logException($ex) {
+       $message = $ex->getMessage();
+       if ($ex->getCode()) {
+               $message .= ' [' . $message . ']';
+       }
+       \OCP\Util::writeLog('index', $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('index', $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('index', $message, \OCP\Util::FATAL);
+               }
+       }
+}
+
 try {
        
        require_once 'lib/base.php';
@@ -30,8 +58,9 @@ try {
        OC::handleRequest();
 
 } catch (Exception $ex) {
+       logException($ex);
+
        //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_Template::printExceptionErrorPage($ex);
 }