@@ -43,88 +43,88 @@ |
||
| 43 | 43 | use Sabre\DAV\Exception\ServiceUnavailable; |
| 44 | 44 | |
| 45 | 45 | class ExceptionLoggerPlugin extends \Sabre\DAV\ServerPlugin { |
| 46 | - protected $nonFatalExceptions = [ |
|
| 47 | - NotAuthenticated::class => true, |
|
| 48 | - // If tokenauth can throw this exception (which is basically as |
|
| 49 | - // NotAuthenticated. So not fatal. |
|
| 50 | - PasswordLoginForbidden::class => true, |
|
| 51 | - // basically a NotAuthenticated |
|
| 52 | - InvalidSyncToken::class => true, |
|
| 53 | - // the sync client uses this to find out whether files exist, |
|
| 54 | - // so it is not always an error, log it as debug |
|
| 55 | - NotFound::class => true, |
|
| 56 | - // this one mostly happens when the same file is uploaded at |
|
| 57 | - // exactly the same time from two clients, only one client |
|
| 58 | - // wins, the second one gets "Precondition failed" |
|
| 59 | - PreconditionFailed::class => true, |
|
| 60 | - // forbidden can be expected when trying to upload to |
|
| 61 | - // read-only folders for example |
|
| 62 | - Forbidden::class => true, |
|
| 63 | - // Happens when an external storage or federated share is temporarily |
|
| 64 | - // not available |
|
| 65 | - StorageNotAvailableException::class => true, |
|
| 66 | - // happens if some a client uses the wrong method for a given URL |
|
| 67 | - // the error message itself is visible on the client side anyways |
|
| 68 | - NotImplemented::class => true, |
|
| 69 | - // happens when the parent directory is not present (for example when a |
|
| 70 | - // move is done to a non-existent directory) |
|
| 71 | - Conflict::class => true, |
|
| 72 | - // happens when a certain method is not allowed to be called |
|
| 73 | - // for example creating a folder that already exists |
|
| 74 | - MethodNotAllowed::class => true, |
|
| 75 | - // A locked file is perfectly valid and can happen in various cases |
|
| 76 | - FileLocked::class => true, |
|
| 77 | - ]; |
|
| 46 | + protected $nonFatalExceptions = [ |
|
| 47 | + NotAuthenticated::class => true, |
|
| 48 | + // If tokenauth can throw this exception (which is basically as |
|
| 49 | + // NotAuthenticated. So not fatal. |
|
| 50 | + PasswordLoginForbidden::class => true, |
|
| 51 | + // basically a NotAuthenticated |
|
| 52 | + InvalidSyncToken::class => true, |
|
| 53 | + // the sync client uses this to find out whether files exist, |
|
| 54 | + // so it is not always an error, log it as debug |
|
| 55 | + NotFound::class => true, |
|
| 56 | + // this one mostly happens when the same file is uploaded at |
|
| 57 | + // exactly the same time from two clients, only one client |
|
| 58 | + // wins, the second one gets "Precondition failed" |
|
| 59 | + PreconditionFailed::class => true, |
|
| 60 | + // forbidden can be expected when trying to upload to |
|
| 61 | + // read-only folders for example |
|
| 62 | + Forbidden::class => true, |
|
| 63 | + // Happens when an external storage or federated share is temporarily |
|
| 64 | + // not available |
|
| 65 | + StorageNotAvailableException::class => true, |
|
| 66 | + // happens if some a client uses the wrong method for a given URL |
|
| 67 | + // the error message itself is visible on the client side anyways |
|
| 68 | + NotImplemented::class => true, |
|
| 69 | + // happens when the parent directory is not present (for example when a |
|
| 70 | + // move is done to a non-existent directory) |
|
| 71 | + Conflict::class => true, |
|
| 72 | + // happens when a certain method is not allowed to be called |
|
| 73 | + // for example creating a folder that already exists |
|
| 74 | + MethodNotAllowed::class => true, |
|
| 75 | + // A locked file is perfectly valid and can happen in various cases |
|
| 76 | + FileLocked::class => true, |
|
| 77 | + ]; |
|
| 78 | 78 | |
| 79 | - /** @var string */ |
|
| 80 | - private $appName; |
|
| 79 | + /** @var string */ |
|
| 80 | + private $appName; |
|
| 81 | 81 | |
| 82 | - /** @var ILogger */ |
|
| 83 | - private $logger; |
|
| 82 | + /** @var ILogger */ |
|
| 83 | + private $logger; |
|
| 84 | 84 | |
| 85 | - /** |
|
| 86 | - * @param string $loggerAppName app name to use when logging |
|
| 87 | - * @param ILogger $logger |
|
| 88 | - */ |
|
| 89 | - public function __construct($loggerAppName, $logger) { |
|
| 90 | - $this->appName = $loggerAppName; |
|
| 91 | - $this->logger = $logger; |
|
| 92 | - } |
|
| 85 | + /** |
|
| 86 | + * @param string $loggerAppName app name to use when logging |
|
| 87 | + * @param ILogger $logger |
|
| 88 | + */ |
|
| 89 | + public function __construct($loggerAppName, $logger) { |
|
| 90 | + $this->appName = $loggerAppName; |
|
| 91 | + $this->logger = $logger; |
|
| 92 | + } |
|
| 93 | 93 | |
| 94 | - /** |
|
| 95 | - * This initializes the plugin. |
|
| 96 | - * |
|
| 97 | - * This function is called by \Sabre\DAV\Server, after |
|
| 98 | - * addPlugin is called. |
|
| 99 | - * |
|
| 100 | - * This method should set up the required event subscriptions. |
|
| 101 | - * |
|
| 102 | - * @param \Sabre\DAV\Server $server |
|
| 103 | - * @return void |
|
| 104 | - */ |
|
| 105 | - public function initialize(\Sabre\DAV\Server $server) { |
|
| 106 | - $server->on('exception', [$this, 'logException'], 10); |
|
| 107 | - } |
|
| 94 | + /** |
|
| 95 | + * This initializes the plugin. |
|
| 96 | + * |
|
| 97 | + * This function is called by \Sabre\DAV\Server, after |
|
| 98 | + * addPlugin is called. |
|
| 99 | + * |
|
| 100 | + * This method should set up the required event subscriptions. |
|
| 101 | + * |
|
| 102 | + * @param \Sabre\DAV\Server $server |
|
| 103 | + * @return void |
|
| 104 | + */ |
|
| 105 | + public function initialize(\Sabre\DAV\Server $server) { |
|
| 106 | + $server->on('exception', [$this, 'logException'], 10); |
|
| 107 | + } |
|
| 108 | 108 | |
| 109 | - /** |
|
| 110 | - * Log exception |
|
| 111 | - * |
|
| 112 | - */ |
|
| 113 | - public function logException(\Throwable $ex) { |
|
| 114 | - $exceptionClass = get_class($ex); |
|
| 115 | - $level = ILogger::FATAL; |
|
| 116 | - if (isset($this->nonFatalExceptions[$exceptionClass]) || |
|
| 117 | - ( |
|
| 118 | - $exceptionClass === ServiceUnavailable::class && |
|
| 119 | - $ex->getMessage() === 'System in maintenance mode.' |
|
| 120 | - ) |
|
| 121 | - ) { |
|
| 122 | - $level = ILogger::DEBUG; |
|
| 123 | - } |
|
| 109 | + /** |
|
| 110 | + * Log exception |
|
| 111 | + * |
|
| 112 | + */ |
|
| 113 | + public function logException(\Throwable $ex) { |
|
| 114 | + $exceptionClass = get_class($ex); |
|
| 115 | + $level = ILogger::FATAL; |
|
| 116 | + if (isset($this->nonFatalExceptions[$exceptionClass]) || |
|
| 117 | + ( |
|
| 118 | + $exceptionClass === ServiceUnavailable::class && |
|
| 119 | + $ex->getMessage() === 'System in maintenance mode.' |
|
| 120 | + ) |
|
| 121 | + ) { |
|
| 122 | + $level = ILogger::DEBUG; |
|
| 123 | + } |
|
| 124 | 124 | |
| 125 | - $this->logger->logException($ex, [ |
|
| 126 | - 'app' => $this->appName, |
|
| 127 | - 'level' => $level, |
|
| 128 | - ]); |
|
| 129 | - } |
|
| 125 | + $this->logger->logException($ex, [ |
|
| 126 | + 'app' => $this->appName, |
|
| 127 | + 'level' => $level, |
|
| 128 | + ]); |
|
| 129 | + } |
|
| 130 | 130 | } |