Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/nextcloud/server.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCôme Chilliet <come.chilliet@nextcloud.com>2022-03-31 16:34:57 +0300
committerCôme Chilliet <come.chilliet@nextcloud.com>2022-05-02 11:52:43 +0300
commite2531f8503dea904dd1cb389ca017ce7bda5ccfc (patch)
tree683918ba234959dd76e771aaae2af434b21d09fe /apps/dav/lib/Connector
parent49b650c4a46c76121d74c6c37c0dbfa0d8f53dbe (diff)
Migrate dav application from ILogger to LoggerInterface
Signed-off-by: Côme Chilliet <come.chilliet@nextcloud.com>
Diffstat (limited to 'apps/dav/lib/Connector')
-rw-r--r--apps/dav/lib/Connector/Sabre/Auth.php3
-rw-r--r--apps/dav/lib/Connector/Sabre/ExceptionLoggerPlugin.php25
-rw-r--r--apps/dav/lib/Connector/Sabre/File.php15
-rw-r--r--apps/dav/lib/Connector/Sabre/ServerFactory.php17
4 files changed, 25 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/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,