]> source.dussan.org Git - nextcloud-server.git/commitdiff
Moved logException to OCP\Util class
authorVincent Petry <pvince81@owncloud.com>
Wed, 23 Oct 2013 08:47:26 +0000 (10:47 +0200)
committerVincent Petry <pvince81@owncloud.com>
Wed, 23 Oct 2013 08:48:27 +0000 (10:48 +0200)
index.php
lib/public/util.php

index 1b9b4a58f7f9fdbfbbe316f223437db328f93d86..ab7333cf0e62593a164e7a7d04ee3d5b0474a765 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';
@@ -58,7 +30,7 @@ try {
        OC::handleRequest();
 
 } catch (Exception $ex) {
-       logException($ex);
+       \OCP\Util::logException($ex);
 
        //show the user a detailed error page
        OC_Response::setStatus(OC_Response::STATUS_INTERNAL_SERVER_ERROR);
index b33f07b55e64396296d06d6cd41b94bee36fce84..00ef863c24c9fac0bc107a229b8f26f2f79fe00d 100644 (file)
@@ -77,6 +77,39 @@ class Util {
                \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( \Exception $ex ) {
+               $message = $ex->getMessage();
+               if ($ex->getCode()) {
+                       $message .= ' [' . $ex->getCode() . ']';
+               }
+               \OCP\Util::writeLog('index', '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('index', '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('index', 'Exception: ' . $message, \OCP\Util::FATAL);
+                       }
+               }
+       }
+
        /**
         * @brief get l10n object
         * @param string $app