]> source.dussan.org Git - nextcloud-server.git/commitdiff
Remove ILogger usages in lib/private/Files/Storage
authorCôme Chilliet <come.chilliet@nextcloud.com>
Thu, 31 Mar 2022 08:57:10 +0000 (10:57 +0200)
committerCôme Chilliet <come.chilliet@nextcloud.com>
Tue, 26 Apr 2022 14:52:53 +0000 (16:52 +0200)
Signed-off-by: Côme Chilliet <come.chilliet@nextcloud.com>
lib/private/Files/Storage/Common.php
lib/private/Files/Storage/DAV.php
lib/private/Files/Storage/Local.php

index 8e7e56e6ca230b1876d10c93dbabbd5a841f4eb9..3c970ee75f5b748c3f2d5bb5ca7ece4270d95ae1 100644 (file)
@@ -61,9 +61,9 @@ use OCP\Files\ReservedWordException;
 use OCP\Files\Storage\ILockingStorage;
 use OCP\Files\Storage\IStorage;
 use OCP\Files\Storage\IWriteStreamStorage;
-use OCP\ILogger;
 use OCP\Lock\ILockingProvider;
 use OCP\Lock\LockedException;
+use Psr\Log\LoggerInterface;
 
 /**
  * Storage backend class for providing common filesystem operation methods
@@ -89,7 +89,9 @@ abstract class Common implements Storage, ILockingStorage, IWriteStreamStorage {
        protected $mountOptions = [];
        protected $owner = null;
 
+       /** @var ?bool */
        private $shouldLogLocks = null;
+       /** @var ?LoggerInterface */
        private $logger;
 
        public function __construct($parameters) {
@@ -237,7 +239,7 @@ abstract class Common implements Storage, ILockingStorage, IWriteStreamStorage {
                        $target = $this->fopen($path2, 'w');
                        [, $result] = \OC_Helper::streamCopy($source, $target);
                        if (!$result) {
-                               \OC::$server->getLogger()->warning("Failed to write data while copying $path1 to $path2");
+                               \OC::$server->get(LoggerInterface::class)->warning("Failed to write data while copying $path1 to $path2");
                        }
                        $this->removeCachedFile($path2);
                        return $result;
@@ -459,11 +461,13 @@ abstract class Common implements Storage, ILockingStorage, IWriteStreamStorage {
                        if ($this->stat('')) {
                                return true;
                        }
-                       \OC::$server->getLogger()->info("External storage not available: stat() failed");
+                       \OC::$server->get(LoggerInterface::class)->info("External storage not available: stat() failed");
                        return false;
                } catch (\Exception $e) {
-                       \OC::$server->getLogger()->warning("External storage not available: " . $e->getMessage());
-                       \OC::$server->getLogger()->logException($e, ['level' => ILogger::WARN]);
+                       \OC::$server->get(LoggerInterface::class)->warning(
+                               "External storage not available: " . $e->getMessage(),
+                               ['exception' => $e]
+                       );
                        return false;
                }
        }
@@ -628,7 +632,7 @@ abstract class Common implements Storage, ILockingStorage, IWriteStreamStorage {
                                        $this->writeStream($targetInternalPath, $source);
                                        $result = true;
                                } catch (\Exception $e) {
-                                       \OC::$server->getLogger()->logException($e, ['level' => ILogger::WARN, 'message' => 'Failed to copy stream to storage']);
+                                       \OC::$server->get(LoggerInterface::class)->warning('Failed to copy stream to storage', ['exception' => $e]);
                                }
                        }
 
@@ -758,7 +762,7 @@ abstract class Common implements Storage, ILockingStorage, IWriteStreamStorage {
                        $provider->acquireLock('files/' . md5($this->getId() . '::' . trim($path, '/')), $type, $this->getId() . '::' . $path);
                } catch (LockedException $e) {
                        if ($logger) {
-                               $logger->logException($e, ['level' => ILogger::INFO]);
+                               $logger->info($e->getMessage(), ['exception' => $e]);
                        }
                        throw $e;
                }
@@ -790,7 +794,7 @@ abstract class Common implements Storage, ILockingStorage, IWriteStreamStorage {
                        $provider->releaseLock('files/' . md5($this->getId() . '::' . trim($path, '/')), $type);
                } catch (LockedException $e) {
                        if ($logger) {
-                               $logger->logException($e, ['level' => ILogger::INFO]);
+                               $logger->info($e->getMessage(), ['exception' => $e]);
                        }
                        throw $e;
                }
@@ -821,15 +825,17 @@ abstract class Common implements Storage, ILockingStorage, IWriteStreamStorage {
                try {
                        $provider->changeLock('files/' . md5($this->getId() . '::' . trim($path, '/')), $type);
                } catch (LockedException $e) {
-                       \OC::$server->getLogger()->logException($e, ['level' => ILogger::INFO]);
+                       if ($logger) {
+                               $logger->info($e->getMessage(), ['exception' => $e]);
+                       }
                        throw $e;
                }
        }
 
-       private function getLockLogger() {
+       private function getLockLogger(): ?LoggerInterface {
                if (is_null($this->shouldLogLocks)) {
                        $this->shouldLogLocks = \OC::$server->getConfig()->getSystemValue('filelocking.debug', false);
-                       $this->logger = $this->shouldLogLocks ? \OC::$server->getLogger() : null;
+                       $this->logger = $this->shouldLogLocks ? \OC::$server->get(LoggerInterface::class) : null;
                }
                return $this->logger;
        }
index b7d1c4bbc1066ae8a23849cb6747caf370d2a6a7..06bec9e39f1b95e4230e3f471341dd2ada51b457 100644 (file)
@@ -50,13 +50,13 @@ use OCP\Files\StorageInvalidException;
 use OCP\Files\StorageNotAvailableException;
 use OCP\Http\Client\IClientService;
 use OCP\ICertificateManager;
-use OCP\ILogger;
 use OCP\Util;
 use Psr\Http\Message\ResponseInterface;
 use Sabre\DAV\Client;
 use Sabre\DAV\Xml\Property\ResourceType;
 use Sabre\HTTP\ClientException;
 use Sabre\HTTP\ClientHttpException;
+use Psr\Log\LoggerInterface;
 
 /**
  * Class DAV
@@ -370,7 +370,7 @@ class DAV extends Common {
                                        if ($response->getStatusCode() === Http::STATUS_LOCKED) {
                                                throw new \OCP\Lock\LockedException($path);
                                        } else {
-                                               Util::writeLog("webdav client", 'Guzzle get returned status code ' . $response->getStatusCode(), ILogger::ERROR);
+                                               \OC::$server->get(LoggerInterface::class)->error('Guzzle get returned status code ' . $response->getStatusCode(), ['app' => 'webdav client']);
                                        }
                                }
 
@@ -843,7 +843,7 @@ class DAV extends Common {
         * @throws ForbiddenException if the action is not allowed
         */
        protected function convertException(Exception $e, $path = '') {
-               \OC::$server->getLogger()->logException($e, ['app' => 'files_external', 'level' => ILogger::DEBUG]);
+               \OC::$server->get(LoggerInterface::class)->debug($e->getMessage(), ['app' => 'files_external', 'exception' => $e]);
                if ($e instanceof ClientHttpException) {
                        if ($e->getHttpStatus() === Http::STATUS_LOCKED) {
                                throw new \OCP\Lock\LockedException($path);
index d637b3d194f56a6998090bf0307ba745aea8e3b5..ee8a8c7d16130c46932de18381a1253064968e5f 100644 (file)
@@ -50,7 +50,7 @@ use OCP\Files\GenericFileException;
 use OCP\Files\IMimeTypeDetector;
 use OCP\Files\Storage\IStorage;
 use OCP\IConfig;
-use OCP\ILogger;
+use Psr\Log\LoggerInterface;
 
 /**
  * for local filestore, we only have to map the paths
@@ -323,17 +323,17 @@ class Local extends \OC\Files\Storage\Common {
                $dstParent = dirname($path2);
 
                if (!$this->isUpdatable($srcParent)) {
-                       \OCP\Util::writeLog('core', 'unable to rename, source directory is not writable : ' . $srcParent, ILogger::ERROR);
+                       \OC::$server->get(LoggerInterface::class)->error('unable to rename, source directory is not writable : ' . $srcParent, ['app' => 'core']);
                        return false;
                }
 
                if (!$this->isUpdatable($dstParent)) {
-                       \OCP\Util::writeLog('core', 'unable to rename, destination directory is not writable : ' . $dstParent, ILogger::ERROR);
+                       \OC::$server->get(LoggerInterface::class)->error('unable to rename, destination directory is not writable : ' . $dstParent, ['app' => 'core']);
                        return false;
                }
 
                if (!$this->file_exists($path1)) {
-                       \OCP\Util::writeLog('core', 'unable to rename, file does not exists : ' . $path1, ILogger::ERROR);
+                       \OC::$server->get(LoggerInterface::class)->error('unable to rename, file does not exists : ' . $path1, ['app' => 'core']);
                        return false;
                }
 
@@ -484,7 +484,7 @@ class Local extends \OC\Files\Storage\Common {
                        return $fullPath;
                }
 
-               \OCP\Util::writeLog('core', "Following symlinks is not allowed ('$fullPath' -> '$realPath' not inside '{$this->realDataDir}')", ILogger::ERROR);
+               \OC::$server->get(LoggerInterface::class)->error("Following symlinks is not allowed ('$fullPath' -> '$realPath' not inside '{$this->realDataDir}')", ['app' => 'core']);
                throw new ForbiddenException('Following symlinks is not allowed', false);
        }