aboutsummaryrefslogtreecommitdiffstats
path: root/lib/private/connector/sabre/exceptionloggerplugin.php
diff options
context:
space:
mode:
authorVincent Petry <pvince81@owncloud.com>2014-01-23 12:11:53 +0100
committerVincent Petry <pvince81@owncloud.com>2014-01-27 11:40:17 +0100
commit11ef12a1060f3e34312ae40c690f95765d7c5f89 (patch)
treeb270925af62a00bef1a5e77448db4fa0a42cf388 /lib/private/connector/sabre/exceptionloggerplugin.php
parent0daabe5b6a2f96e8b754c2414bb83d00277a307a (diff)
downloadnextcloud-server-11ef12a1060f3e34312ae40c690f95765d7c5f89.tar.gz
nextcloud-server-11ef12a1060f3e34312ae40c690f95765d7c5f89.zip
Added exception logger plugin for sabre connector
Whenever an exception occurs in the sabre connector code or code called by it, it will be logged. This plugin approach is needed because Sabre already catches exceptions to return them to the client in the XML response, so they don't appear logged in the web server log. This will make it much easier to debug syncing issues.
Diffstat (limited to 'lib/private/connector/sabre/exceptionloggerplugin.php')
-rw-r--r--lib/private/connector/sabre/exceptionloggerplugin.php50
1 files changed, 50 insertions, 0 deletions
diff --git a/lib/private/connector/sabre/exceptionloggerplugin.php b/lib/private/connector/sabre/exceptionloggerplugin.php
new file mode 100644
index 00000000000..8e77afaf207
--- /dev/null
+++ b/lib/private/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);
+ }
+ }
+}