diff options
Diffstat (limited to 'apps/dav/lib/Connector')
-rw-r--r-- | apps/dav/lib/Connector/Sabre/Auth.php | 3 | ||||
-rw-r--r-- | apps/dav/lib/Connector/Sabre/Directory.php | 6 | ||||
-rw-r--r-- | apps/dav/lib/Connector/Sabre/ExceptionLoggerPlugin.php | 25 | ||||
-rw-r--r-- | apps/dav/lib/Connector/Sabre/File.php | 15 | ||||
-rw-r--r-- | apps/dav/lib/Connector/Sabre/ServerFactory.php | 17 |
5 files changed, 31 insertions, 35 deletions
diff --git a/apps/dav/lib/Connector/Sabre/Auth.php b/apps/dav/lib/Connector/Sabre/Auth.php index df4e3c65ce0..d81a3f9d667 100644 --- a/apps/dav/lib/Connector/Sabre/Auth.php +++ b/apps/dav/lib/Connector/Sabre/Auth.php @@ -41,6 +41,7 @@ use OC\User\Session; use OCA\DAV\Connector\Sabre\Exception\PasswordLoginForbidden; use OCP\IRequest; use OCP\ISession; +use Psr\Log\LoggerInterface; use Sabre\DAV\Auth\Backend\AbstractBasic; use Sabre\DAV\Exception\NotAuthenticated; use Sabre\DAV\Exception\ServiceUnavailable; @@ -157,7 +158,7 @@ class Auth extends AbstractBasic { } catch (Exception $e) { $class = get_class($e); $msg = $e->getMessage(); - \OC::$server->getLogger()->logException($e); + \OC::$server->get(LoggerInterface::class)->error($e->getMessage(), ['exception' => $e]); throw new ServiceUnavailable("$class: $msg"); } } diff --git a/apps/dav/lib/Connector/Sabre/Directory.php b/apps/dav/lib/Connector/Sabre/Directory.php index 9e0b89596cd..ed98b5050f8 100644 --- a/apps/dav/lib/Connector/Sabre/Directory.php +++ b/apps/dav/lib/Connector/Sabre/Directory.php @@ -47,6 +47,7 @@ use OCP\Files\NotPermittedException; use OCP\Files\StorageNotAvailableException; use OCP\Lock\ILockingProvider; use OCP\Lock\LockedException; +use Psr\Log\LoggerInterface; use Sabre\DAV\Exception\BadRequest; use Sabre\DAV\Exception\Locked; use Sabre\DAV\Exception\NotFound; @@ -331,6 +332,8 @@ class Directory extends \OCA\DAV\Connector\Sabre\Node implements \Sabre\DAV\ICol * @return array */ public function getQuotaInfo() { + /** @var LoggerInterface $logger */ + $logger = \OC::$server->get(LoggerInterface::class); if ($this->quotaInfo) { return $this->quotaInfo; } @@ -347,10 +350,13 @@ class Directory extends \OCA\DAV\Connector\Sabre\Node implements \Sabre\DAV\ICol ]; return $this->quotaInfo; } catch (\OCP\Files\NotFoundException $e) { + $logger->warning("error while getting quota into", ['exception' => $e]); return [0, 0]; } catch (\OCP\Files\StorageNotAvailableException $e) { + $logger->warning("error while getting quota into", ['exception' => $e]); return [0, 0]; } catch (NotPermittedException $e) { + $logger->warning("error while getting quota into", ['exception' => $e]); return [0, 0]; } } diff --git a/apps/dav/lib/Connector/Sabre/ExceptionLoggerPlugin.php b/apps/dav/lib/Connector/Sabre/ExceptionLoggerPlugin.php index b4df1f582db..e89ce3a8037 100644 --- a/apps/dav/lib/Connector/Sabre/ExceptionLoggerPlugin.php +++ b/apps/dav/lib/Connector/Sabre/ExceptionLoggerPlugin.php @@ -30,7 +30,7 @@ namespace OCA\DAV\Connector\Sabre; use OCA\DAV\Connector\Sabre\Exception\FileLocked; use OCA\DAV\Connector\Sabre\Exception\PasswordLoginForbidden; use OCP\Files\StorageNotAvailableException; -use OCP\ILogger; +use Psr\Log\LoggerInterface; use Sabre\DAV\Exception\BadRequest; use Sabre\DAV\Exception\Conflict; use Sabre\DAV\Exception\Forbidden; @@ -86,14 +86,13 @@ class ExceptionLoggerPlugin extends \Sabre\DAV\ServerPlugin { /** @var string */ private $appName; - /** @var ILogger */ - private $logger; + private LoggerInterface $logger; /** * @param string $loggerAppName app name to use when logging - * @param ILogger $logger + * @param LoggerInterface $logger */ - public function __construct($loggerAppName, $logger) { + public function __construct($loggerAppName, LoggerInterface $logger) { $this->appName = $loggerAppName; $this->logger = $logger; } @@ -119,19 +118,21 @@ class ExceptionLoggerPlugin extends \Sabre\DAV\ServerPlugin { */ public function logException(\Throwable $ex) { $exceptionClass = get_class($ex); - $level = ILogger::FATAL; if (isset($this->nonFatalExceptions[$exceptionClass]) || ( $exceptionClass === ServiceUnavailable::class && $ex->getMessage() === 'System in maintenance mode.' ) ) { - $level = ILogger::DEBUG; + $this->logger->debug($ex->getMessage(), [ + 'app' => $this->appName, + 'exception' => $ex, + ]); + } else { + $this->logger->critical($ex->getMessage(), [ + 'app' => $this->appName, + 'exception' => $ex, + ]); } - - $this->logger->logException($ex, [ - 'app' => $this->appName, - 'level' => $level, - ]); } } diff --git a/apps/dav/lib/Connector/Sabre/File.php b/apps/dav/lib/Connector/Sabre/File.php index 6c379984995..37fb109a3bd 100644 --- a/apps/dav/lib/Connector/Sabre/File.php +++ b/apps/dav/lib/Connector/Sabre/File.php @@ -63,11 +63,11 @@ use OCP\Files\NotPermittedException; use OCP\Files\Storage; use OCP\Files\StorageNotAvailableException; use OCP\IL10N; -use OCP\ILogger; use OCP\L10N\IFactory as IL10NFactory; use OCP\Lock\ILockingProvider; use OCP\Lock\LockedException; use OCP\Share\IManager; +use Psr\Log\LoggerInterface; use Sabre\DAV\Exception; use Sabre\DAV\Exception\BadRequest; use Sabre\DAV\Exception\Forbidden; @@ -251,7 +251,7 @@ class File extends Node implements IFile { } else { $target = $partStorage->fopen($internalPartPath, 'wb'); if ($target === false) { - \OC::$server->getLogger()->error('\OC\Files\Filesystem::fopen() failed', ['app' => 'webdav']); + \OC::$server->get(LoggerInterface::class)->error('\OC\Files\Filesystem::fopen() failed', ['app' => 'webdav']); // because we have no clue about the cause we can only throw back a 500/Internal Server Error throw new Exception($this->l10n->t('Could not write file contents')); } @@ -295,13 +295,12 @@ class File extends Node implements IFile { } } } catch (\Exception $e) { - $context = []; - if ($e instanceof LockedException) { - $context['level'] = ILogger::DEBUG; + \OC::$server->get(LoggerInterface::class)->debug($e->getMessage(), ['exception' => $e]); + } else { + \OC::$server->get(LoggerInterface::class)->error($e->getMessage(), ['exception' => $e]); } - \OC::$server->getLogger()->logException($e, $context); if ($needsPartFile) { $partStorage->unlink($internalPartPath); } @@ -340,7 +339,7 @@ class File extends Node implements IFile { $renameOkay = $storage->moveFromStorage($partStorage, $internalPartPath, $internalPath); $fileExists = $storage->file_exists($internalPath); if ($renameOkay === false || $fileExists === false) { - \OC::$server->getLogger()->error('renaming part file to final file failed $renameOkay: ' . ($renameOkay ? 'true' : 'false') . ', $fileExists: ' . ($fileExists ? 'true' : 'false') . ')', ['app' => 'webdav']); + \OC::$server->get(LoggerInterface::class)->error('renaming part file to final file failed $renameOkay: ' . ($renameOkay ? 'true' : 'false') . ', $fileExists: ' . ($fileExists ? 'true' : 'false') . ')', ['app' => 'webdav']); throw new Exception($this->l10n->t('Could not rename part file to final file')); } } catch (ForbiddenException $ex) { @@ -626,7 +625,7 @@ class File extends Node implements IFile { $renameOkay = $targetStorage->moveFromStorage($partStorage, $partInternalPath, $targetInternalPath); $fileExists = $targetStorage->file_exists($targetInternalPath); if ($renameOkay === false || $fileExists === false) { - \OC::$server->getLogger()->error('\OC\Files\Filesystem::rename() failed', ['app' => 'webdav']); + \OC::$server->get(LoggerInterface::class)->error('\OC\Files\Filesystem::rename() failed', ['app' => 'webdav']); // only delete if an error occurred and the target file was already created if ($fileExists) { // set to null to avoid double-deletion when handling exception diff --git a/apps/dav/lib/Connector/Sabre/ServerFactory.php b/apps/dav/lib/Connector/Sabre/ServerFactory.php index b13dbd20ca9..635645ed992 100644 --- a/apps/dav/lib/Connector/Sabre/ServerFactory.php +++ b/apps/dav/lib/Connector/Sabre/ServerFactory.php @@ -38,20 +38,19 @@ use OCP\Files\Mount\IMountManager; use OCP\IConfig; use OCP\IDBConnection; use OCP\IL10N; -use OCP\ILogger; use OCP\IPreview; use OCP\IRequest; use OCP\ITagManager; use OCP\IUserSession; use OCP\SabrePluginEvent; +use Psr\Log\LoggerInterface; use Sabre\DAV\Auth\Plugin; use Symfony\Component\EventDispatcher\EventDispatcherInterface; class ServerFactory { /** @var IConfig */ private $config; - /** @var ILogger */ - private $logger; + private LoggerInterface $logger; /** @var IDBConnection */ private $databaseConnection; /** @var IUserSession */ @@ -69,19 +68,9 @@ class ServerFactory { /** @var IL10N */ private $l10n; - /** - * @param IConfig $config - * @param ILogger $logger - * @param IDBConnection $databaseConnection - * @param IUserSession $userSession - * @param IMountManager $mountManager - * @param ITagManager $tagManager - * @param IRequest $request - * @param IPreview $previewManager - */ public function __construct( IConfig $config, - ILogger $logger, + LoggerInterface $logger, IDBConnection $databaseConnection, IUserSession $userSession, IMountManager $mountManager, |