[Pkg-owncloud-commits] [owncloud] 62/66: Backported logException from stable6

David Prévot taffit at moszumanska.debian.org
Fri Apr 18 22:49:49 UTC 2014


This is an automated email from the git hooks/post-receive script.

taffit pushed a commit to annotated tag v5.0.15
in repository owncloud.

commit e31a3d0f87f4f9eea64de23456850f0df23c54ff
Author: Vincent Petry <pvince81 at owncloud.com>
Date:   Thu Feb 27 16:33:57 2014 +0100

    Backported logException from stable6
---
 lib/public/util.php | 37 +++++++++++++++++++++++++++++++++++++
 1 file changed, 37 insertions(+)

diff --git a/lib/public/util.php b/lib/public/util.php
index db07cbc..7fc59f3 100644
--- a/lib/public/util.php
+++ b/lib/public/util.php
@@ -78,6 +78,43 @@ class Util {
 	}
 
 	/**
+	 * write exception into the log. Include the stack trace
+	 * if DEBUG mode is enabled
+	 * @param string $app app name
+	 * @param Exception $ex exception to log
+	 */
+	public static function logException( $app, \Exception $ex ) {
+		$class = get_class($ex);
+		if ($class !== 'Exception') {
+			$message = $class . ': ';
+		}
+		$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("\n", $ex->getTraceAsString());
+			// first element is empty
+			array_shift($stack);
+			foreach ($stack as $s) {
+				\OCP\Util::writeLog($app, 'Exception: ' . $s, \OCP\Util::FATAL);
+			}
+
+			// include cause
+			while (method_exists($ex, 'getPrevious') && $ex = $ex->getPrevious()) {
+				$message .= ' - Caused by:' . ' ';
+				$message .= $ex->getMessage();
+				if ($ex->getCode()) {
+					$message .= '[' . $ex->getCode() . '] ';
+				}
+				\OCP\Util::writeLog($app, 'Exception: ' . $message, \OCP\Util::FATAL);
+			}
+		}
+	}
+
+	/**
 	 * @brief add a css file
 	 * @param string $url
 	 */

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-owncloud/owncloud.git



More information about the Pkg-owncloud-commits mailing list