diff options
-rw-r--r-- | apps/files/appinfo/remote.php | 1 | ||||
-rw-r--r-- | lib/connector/sabre/exceptionloggerplugin.php | 50 | ||||
-rw-r--r-- | lib/connector/sabre/file.php | 2 | ||||
-rw-r--r-- | lib/public/util.php | 37 |
4 files changed, 89 insertions, 1 deletions
diff --git a/apps/files/appinfo/remote.php b/apps/files/appinfo/remote.php index a1444141099..4cecaf207fd 100644 --- a/apps/files/appinfo/remote.php +++ b/apps/files/appinfo/remote.php @@ -49,6 +49,7 @@ $server->addPlugin(new Sabre_DAV_Locks_Plugin($lockBackend)); $server->addPlugin(new Sabre_DAV_Browser_Plugin(false)); // Show something in the Browser, but no upload $server->addPlugin(new OC_Connector_Sabre_QuotaPlugin()); $server->addPlugin(new OC_Connector_Sabre_MaintenancePlugin()); +$server->addPlugin(new OC_Connector_Sabre_ExceptionLoggerPlugin('webdav')); // And off we go! $server->exec(); diff --git a/lib/connector/sabre/exceptionloggerplugin.php b/lib/connector/sabre/exceptionloggerplugin.php new file mode 100644 index 00000000000..8e77afaf207 --- /dev/null +++ b/lib/connector/sabre/exceptionloggerplugin.php @@ -0,0 +1,50 @@ +<?php + +/** + * ownCloud + * + * @author Vincent Petry + * @copyright 2014 Vincent Petry <pvince81@owncloud.com> + * + * @license AGPL3 + */ + +class OC_Connector_Sabre_ExceptionLoggerPlugin extends Sabre_DAV_ServerPlugin +{ + private $appName; + + /** + * @param string $loggerAppName app name to use when logging + */ + public function __construct($loggerAppName = 'webdav') { + $this->appName = $loggerAppName; + } + + /** + * This initializes the plugin. + * + * This function is called by Sabre_DAV_Server, after + * addPlugin is called. + * + * This method should set up the required event subscriptions. + * + * @param Sabre_DAV_Server $server + * @return void + */ + public function initialize(Sabre_DAV_Server $server) { + + $server->subscribeEvent('exception', array($this, 'logException'), 10); + } + + /** + * Log exception + * + * @internal param Exception $e exception + */ + public function logException($e) { + $exceptionClass = get_class($e); + if ($exceptionClass !== 'Sabre_DAV_Exception_NotAuthenticated') { + \OCP\Util::logException($this->appName, $e); + } + } +} diff --git a/lib/connector/sabre/file.php b/lib/connector/sabre/file.php index bbfb27a8a9e..d3974be15a3 100644 --- a/lib/connector/sabre/file.php +++ b/lib/connector/sabre/file.php @@ -81,7 +81,7 @@ class OC_Connector_Sabre_File extends OC_Connector_Sabre_Node implements Sabre_D if ($renameOkay === false || $fileExists === false) { \OC_Log::write('webdav', '\OC\Files\Filesystem::rename() failed', \OC_Log::ERROR); \OC\Files\Filesystem::unlink($partpath); - throw new Sabre_DAV_Exception(); + throw new Sabre_DAV_Exception('Could not rename part file to final file'); } diff --git a/lib/public/util.php b/lib/public/util.php index db07cbcfff3..7fc59f38bec 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 */ |