server/lib/private/connector/sabre/exceptionloggerplugin.php
Vincent Petry 11ef12a106 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.
2014-01-27 11:40:17 +01:00

50 lines
1 KiB
PHP

<?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);
}
}
}