2014-01-23 15:11:53 +04:00
|
|
|
<?php
|
|
|
|
|
|
|
|
/**
|
|
|
|
* ownCloud
|
|
|
|
*
|
|
|
|
* @author Vincent Petry
|
|
|
|
* @copyright 2014 Vincent Petry <pvince81@owncloud.com>
|
|
|
|
*
|
|
|
|
* @license AGPL3
|
|
|
|
*/
|
|
|
|
|
2014-01-09 17:25:48 +04:00
|
|
|
class OC_Connector_Sabre_ExceptionLoggerPlugin extends \Sabre\DAV\ServerPlugin
|
2014-01-23 15:11:53 +04:00
|
|
|
{
|
2014-05-05 13:31:25 +04:00
|
|
|
private $nonFatalExceptions = array(
|
2014-01-09 17:25:48 +04:00
|
|
|
'Sabre\DAV\Exception\NotAuthenticated' => true,
|
2014-05-05 13:31:25 +04:00
|
|
|
// the sync client uses this to find out whether files exist,
|
|
|
|
// so it is not always an error, log it as debug
|
2014-01-09 17:25:48 +04:00
|
|
|
'Sabre\DAV\Exception\NotFound' => true,
|
2014-05-05 13:31:25 +04:00
|
|
|
// this one mostly happens when the same file is uploaded at
|
|
|
|
// exactly the same time from two clients, only one client
|
|
|
|
// wins, the second one gets "Precondition failed"
|
2014-01-09 17:25:48 +04:00
|
|
|
'Sabre\DAV\Exception\PreconditionFailed' => true,
|
2014-05-05 13:31:25 +04:00
|
|
|
);
|
|
|
|
|
2014-01-23 15:11:53 +04:00
|
|
|
private $appName;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param string $loggerAppName app name to use when logging
|
|
|
|
*/
|
|
|
|
public function __construct($loggerAppName = 'webdav') {
|
|
|
|
$this->appName = $loggerAppName;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* This initializes the plugin.
|
|
|
|
*
|
2014-01-09 17:25:48 +04:00
|
|
|
* This function is called by \Sabre\DAV\Server, after
|
2014-01-23 15:11:53 +04:00
|
|
|
* addPlugin is called.
|
|
|
|
*
|
|
|
|
* This method should set up the required event subscriptions.
|
|
|
|
*
|
2014-01-09 17:25:48 +04:00
|
|
|
* @param \Sabre\DAV\Server $server
|
2014-01-23 15:11:53 +04:00
|
|
|
* @return void
|
|
|
|
*/
|
2014-01-09 17:25:48 +04:00
|
|
|
public function initialize(\Sabre\DAV\Server $server) {
|
2014-01-23 15:11:53 +04:00
|
|
|
|
|
|
|
$server->subscribeEvent('exception', array($this, 'logException'), 10);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Log exception
|
|
|
|
*
|
|
|
|
* @internal param Exception $e exception
|
|
|
|
*/
|
|
|
|
public function logException($e) {
|
|
|
|
$exceptionClass = get_class($e);
|
2014-05-05 13:31:25 +04:00
|
|
|
$level = \OCP\Util::FATAL;
|
|
|
|
if (isset($this->nonFatalExceptions[$exceptionClass])) {
|
|
|
|
$level = \OCP\Util::DEBUG;
|
2014-01-23 15:11:53 +04:00
|
|
|
}
|
2014-05-05 13:31:25 +04:00
|
|
|
\OCP\Util::logException($this->appName, $e, $level);
|
2014-01-23 15:11:53 +04:00
|
|
|
}
|
|
|
|
}
|