diff options
author | Côme Chilliet <91878298+come-nc@users.noreply.github.com> | 2022-03-29 09:39:38 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-03-29 09:39:38 +0200 |
commit | 765999f454c0c5ebd8f2aa693d123f62d104d37a (patch) | |
tree | ee986c4dcb0edac3babb7ee87e5afc159087e2e0 /lib/private/Files | |
parent | 4a4f250a2b733f915e8b465bc995ea8ac18a8fbc (diff) | |
parent | 6d354595f71f15f3d15bce70683b4bc013a6bfaf (diff) | |
download | nextcloud-server-765999f454c0c5ebd8f2aa693d123f62d104d37a.tar.gz nextcloud-server-765999f454c0c5ebd8f2aa693d123f62d104d37a.zip |
Merge pull request #31609 from nextcloud/fix/migrate-away-from-ilogger
Migrate from ILogger to LoggerInterface in lib/private
Diffstat (limited to 'lib/private/Files')
-rw-r--r-- | lib/private/Files/Cache/Cache.php | 5 | ||||
-rw-r--r-- | lib/private/Files/Cache/CacheQueryBuilder.php | 4 | ||||
-rw-r--r-- | lib/private/Files/Cache/QuerySearchHelper.php | 7 | ||||
-rw-r--r-- | lib/private/Files/Config/UserMountCache.php | 13 | ||||
-rw-r--r-- | lib/private/Files/Mount/ObjectStorePreviewCacheMountProvider.php | 7 | ||||
-rw-r--r-- | lib/private/Files/Node/Root.php | 9 | ||||
-rw-r--r-- | lib/private/Files/ObjectStore/Swift.php | 3 | ||||
-rw-r--r-- | lib/private/Files/ObjectStore/SwiftFactory.php | 10 | ||||
-rw-r--r-- | lib/private/Files/Storage/Wrapper/Encryption.php | 24 | ||||
-rw-r--r-- | lib/private/Files/Type/Detection.php | 13 | ||||
-rw-r--r-- | lib/private/Files/Utils/Scanner.php | 11 |
11 files changed, 37 insertions, 69 deletions
diff --git a/lib/private/Files/Cache/Cache.php b/lib/private/Files/Cache/Cache.php index 7c2e635549a..949079dfa22 100644 --- a/lib/private/Files/Cache/Cache.php +++ b/lib/private/Files/Cache/Cache.php @@ -58,6 +58,7 @@ use OCP\Files\Search\ISearchOperator; use OCP\Files\Search\ISearchQuery; use OCP\Files\Storage\IStorage; use OCP\IDBConnection; +use Psr\Log\LoggerInterface; /** * Metadata cache for a storage @@ -128,7 +129,7 @@ class Cache implements ICache { return new CacheQueryBuilder( $this->connection, \OC::$server->getSystemConfig(), - \OC::$server->getLogger() + \OC::$server->get(LoggerInterface::class) ); } @@ -590,7 +591,7 @@ class Cache implements ICache { $query = $this->getQueryBuilder(); $query->delete('filecache_extended') ->where($query->expr()->in('fileid', $query->createParameter('childIds'))); - + foreach (array_chunk($childIds, 1000) as $childIdChunk) { $query->setParameter('childIds', $childIdChunk, IQueryBuilder::PARAM_INT_ARRAY); $query->execute(); diff --git a/lib/private/Files/Cache/CacheQueryBuilder.php b/lib/private/Files/Cache/CacheQueryBuilder.php index 87a1f940f20..b5a9101877c 100644 --- a/lib/private/Files/Cache/CacheQueryBuilder.php +++ b/lib/private/Files/Cache/CacheQueryBuilder.php @@ -29,7 +29,7 @@ use OC\DB\QueryBuilder\QueryBuilder; use OC\SystemConfig; use OCP\DB\QueryBuilder\IQueryBuilder; use OCP\IDBConnection; -use OCP\ILogger; +use Psr\Log\LoggerInterface; /** * Query builder with commonly used helpers for filecache queries @@ -37,7 +37,7 @@ use OCP\ILogger; class CacheQueryBuilder extends QueryBuilder { private $alias = null; - public function __construct(IDBConnection $connection, SystemConfig $systemConfig, ILogger $logger) { + public function __construct(IDBConnection $connection, SystemConfig $systemConfig, LoggerInterface $logger) { parent::__construct($connection, $systemConfig, $logger); } diff --git a/lib/private/Files/Cache/QuerySearchHelper.php b/lib/private/Files/Cache/QuerySearchHelper.php index e065e95e4fd..3bf9abf3524 100644 --- a/lib/private/Files/Cache/QuerySearchHelper.php +++ b/lib/private/Files/Cache/QuerySearchHelper.php @@ -34,7 +34,7 @@ use OCP\Files\IMimeTypeLoader; use OCP\Files\Search\ISearchBinaryOperator; use OCP\Files\Search\ISearchQuery; use OCP\IDBConnection; -use OCP\ILogger; +use Psr\Log\LoggerInterface; class QuerySearchHelper { @@ -44,8 +44,7 @@ class QuerySearchHelper { private $connection; /** @var SystemConfig */ private $systemConfig; - /** @var ILogger */ - private $logger; + private LoggerInterface $logger; /** @var SearchBuilder */ private $searchBuilder; /** @var QueryOptimizer */ @@ -55,7 +54,7 @@ class QuerySearchHelper { IMimeTypeLoader $mimetypeLoader, IDBConnection $connection, SystemConfig $systemConfig, - ILogger $logger, + LoggerInterface $logger, SearchBuilder $searchBuilder, QueryOptimizer $queryOptimizer ) { diff --git a/lib/private/Files/Config/UserMountCache.php b/lib/private/Files/Config/UserMountCache.php index 9a5eddc4878..666ba9b065b 100644 --- a/lib/private/Files/Config/UserMountCache.php +++ b/lib/private/Files/Config/UserMountCache.php @@ -38,9 +38,9 @@ use OCP\Files\Mount\IMountPoint; use OCP\Files\NotFoundException; use OCP\ICache; use OCP\IDBConnection; -use OCP\ILogger; use OCP\IUser; use OCP\IUserManager; +use Psr\Log\LoggerInterface; /** * Cache mounts points per user in the cache so we can easilly look them up @@ -64,10 +64,7 @@ class UserMountCache implements IUserMountCache { **/ private $mountsForUsers; - /** - * @var ILogger - */ - private $logger; + private LoggerInterface $logger; /** * @var ICache @@ -76,12 +73,8 @@ class UserMountCache implements IUserMountCache { /** * UserMountCache constructor. - * - * @param IDBConnection $connection - * @param IUserManager $userManager - * @param ILogger $logger */ - public function __construct(IDBConnection $connection, IUserManager $userManager, ILogger $logger) { + public function __construct(IDBConnection $connection, IUserManager $userManager, LoggerInterface $logger) { $this->connection = $connection; $this->userManager = $userManager; $this->logger = $logger; diff --git a/lib/private/Files/Mount/ObjectStorePreviewCacheMountProvider.php b/lib/private/Files/Mount/ObjectStorePreviewCacheMountProvider.php index 0043503f2cd..3a20afba5a5 100644 --- a/lib/private/Files/Mount/ObjectStorePreviewCacheMountProvider.php +++ b/lib/private/Files/Mount/ObjectStorePreviewCacheMountProvider.php @@ -31,18 +31,17 @@ use OC\Files\Storage\Wrapper\Jail; use OCP\Files\Config\IRootMountProvider; use OCP\Files\Storage\IStorageFactory; use OCP\IConfig; -use OCP\ILogger; +use Psr\Log\LoggerInterface; /** * Mount provider for object store app data folder for previews */ class ObjectStorePreviewCacheMountProvider implements IRootMountProvider { - /** @var ILogger */ - private $logger; + private LoggerInterface $logger; /** @var IConfig */ private $config; - public function __construct(ILogger $logger, IConfig $config) { + public function __construct(LoggerInterface $logger, IConfig $config) { $this->logger = $logger; $this->config = $config; } diff --git a/lib/private/Files/Node/Root.php b/lib/private/Files/Node/Root.php index 53162737b6f..a8b36ee7731 100644 --- a/lib/private/Files/Node/Root.php +++ b/lib/private/Files/Node/Root.php @@ -44,9 +44,9 @@ use OCP\Files\Events\Node\FilesystemTornDownEvent; use OCP\Files\IRootFolder; use OCP\Files\NotFoundException; use OCP\Files\NotPermittedException; -use OCP\ILogger; use OCP\IUser; use OCP\IUserManager; +use Psr\Log\LoggerInterface; /** * Class Root @@ -73,7 +73,7 @@ class Root extends Folder implements IRootFolder { private ?IUser $user; private CappedMemoryCache $userFolderCache; private IUserMountCache $userMountCache; - private ILogger $logger; + private LoggerInterface $logger; private IUserManager $userManager; private IEventDispatcher $eventDispatcher; @@ -81,16 +81,13 @@ class Root extends Folder implements IRootFolder { * @param Manager $manager * @param View $view * @param IUser|null $user - * @param IUserMountCache $userMountCache - * @param ILogger $logger - * @param IUserManager $userManager */ public function __construct( $manager, $view, $user, IUserMountCache $userMountCache, - ILogger $logger, + LoggerInterface $logger, IUserManager $userManager, IEventDispatcher $eventDispatcher ) { diff --git a/lib/private/Files/ObjectStore/Swift.php b/lib/private/Files/ObjectStore/Swift.php index a3c8d92f3d2..b463cb9d44d 100644 --- a/lib/private/Files/ObjectStore/Swift.php +++ b/lib/private/Files/ObjectStore/Swift.php @@ -32,6 +32,7 @@ use Icewind\Streams\RetryWrapper; use OCP\Files\NotFoundException; use OCP\Files\ObjectStore\IObjectStore; use OCP\Files\StorageAuthException; +use Psr\Log\LoggerInterface; const SWIFT_SEGMENT_SIZE = 1073741824; // 1GB @@ -48,7 +49,7 @@ class Swift implements IObjectStore { $this->swiftFactory = $connectionFactory ?: new SwiftFactory( \OC::$server->getMemCacheFactory()->createDistributed('swift::'), $params, - \OC::$server->getLogger() + \OC::$server->get(LoggerInterface::class) ); $this->params = $params; } diff --git a/lib/private/Files/ObjectStore/SwiftFactory.php b/lib/private/Files/ObjectStore/SwiftFactory.php index df4b5a93678..bd75ccada2e 100644 --- a/lib/private/Files/ObjectStore/SwiftFactory.php +++ b/lib/private/Files/ObjectStore/SwiftFactory.php @@ -40,7 +40,6 @@ use GuzzleHttp\HandlerStack; use OCP\Files\StorageAuthException; use OCP\Files\StorageNotAvailableException; use OCP\ICache; -use OCP\ILogger; use OpenStack\Common\Auth\Token; use OpenStack\Common\Error\BadResponseError; use OpenStack\Common\Transport\Utils as TransportUtils; @@ -50,13 +49,14 @@ use OpenStack\Identity\v3\Service as IdentityV3Service; use OpenStack\ObjectStore\v1\Models\Container; use OpenStack\OpenStack; use Psr\Http\Message\RequestInterface; +use Psr\Log\LoggerInterface; class SwiftFactory { private $cache; private $params; /** @var Container|null */ private $container = null; - private $logger; + private LoggerInterface $logger; public const DEFAULT_OPTIONS = [ 'autocreate' => false, @@ -65,7 +65,7 @@ class SwiftFactory { 'catalogType' => 'object-store' ]; - public function __construct(ICache $cache, array $params, ILogger $logger) { + public function __construct(ICache $cache, array $params, LoggerInterface $logger) { $this->cache = $cache; $this->params = $params; $this->logger = $logger; @@ -203,7 +203,7 @@ class SwiftFactory { $this->logger->debug('Cached token for swift expired'); } } catch (\Exception $e) { - $this->logger->logException($e); + $this->logger->error($e->getMessage(), ['exception' => $e]); } } } @@ -279,7 +279,7 @@ class SwiftFactory { /** @var RequestInterface $request */ $request = $e->getRequest(); $host = $request->getUri()->getHost() . ':' . $request->getUri()->getPort(); - \OC::$server->getLogger()->error("Can't connect to object storage server at $host"); + $this->logger->error("Can't connect to object storage server at $host", ['exception' => $e]); throw new StorageNotAvailableException("Can't connect to object storage server at $host", StorageNotAvailableException::STATUS_ERROR, $e); } } diff --git a/lib/private/Files/Storage/Wrapper/Encryption.php b/lib/private/Files/Storage/Wrapper/Encryption.php index 75611d1ab0f..4cfe932cc9f 100644 --- a/lib/private/Files/Storage/Wrapper/Encryption.php +++ b/lib/private/Files/Storage/Wrapper/Encryption.php @@ -50,7 +50,7 @@ use OCP\Encryption\Keys\IStorage; use OCP\Files\Cache\ICacheEntry; use OCP\Files\Mount\IMountPoint; use OCP\Files\Storage; -use OCP\ILogger; +use Psr\Log\LoggerInterface; class Encryption extends Wrapper { use LocalTempFileTrait; @@ -64,8 +64,7 @@ class Encryption extends Wrapper { /** @var \OCP\Encryption\IManager */ private $encryptionManager; - /** @var \OCP\ILogger */ - private $logger; + private LoggerInterface $logger; /** @var string */ private $uid; @@ -96,21 +95,12 @@ class Encryption extends Wrapper { /** * @param array $parameters - * @param IManager $encryptionManager - * @param Util $util - * @param ILogger $logger - * @param IFile $fileHelper - * @param string $uid - * @param IStorage $keyStorage - * @param Update $update - * @param Manager $mountManager - * @param ArrayCache $arrayCache */ public function __construct( $parameters, IManager $encryptionManager = null, Util $util = null, - ILogger $logger = null, + LoggerInterface $logger = null, IFile $fileHelper = null, $uid = null, IStorage $keyStorage = null, @@ -448,9 +438,8 @@ class Encryption extends Wrapper { } } } catch (ModuleDoesNotExistsException $e) { - $this->logger->logException($e, [ - 'message' => 'Encryption module "' . $encryptionModuleId . '" not found, file will be stored unencrypted', - 'level' => ILogger::WARN, + $this->logger->warning('Encryption module "' . $encryptionModuleId . '" not found, file will be stored unencrypted', [ + 'exception' => $e, 'app' => 'core', ]); } @@ -503,8 +492,7 @@ class Encryption extends Wrapper { try { $result = $this->fixUnencryptedSize($path, $size, $unencryptedSize); } catch (\Exception $e) { - $this->logger->error('Couldn\'t re-calculate unencrypted size for ' . $path); - $this->logger->logException($e); + $this->logger->error('Couldn\'t re-calculate unencrypted size for ' . $path, ['exception' => $e]); } unset($this->fixUnencryptedSizeOf[$this->getFullPath($path)]); } diff --git a/lib/private/Files/Type/Detection.php b/lib/private/Files/Type/Detection.php index bd2bfb5f939..4cade024460 100644 --- a/lib/private/Files/Type/Detection.php +++ b/lib/private/Files/Type/Detection.php @@ -42,8 +42,8 @@ declare(strict_types=1); namespace OC\Files\Type; use OCP\Files\IMimeTypeDetector; -use OCP\ILogger; use OCP\IURLGenerator; +use Psr\Log\LoggerInterface; /** * Class Detection @@ -66,8 +66,7 @@ class Detection implements IMimeTypeDetector { /** @var IURLGenerator */ private $urlGenerator; - /** @var ILogger */ - private $logger; + private LoggerInterface $logger; /** @var string */ private $customConfigDir; @@ -75,14 +74,8 @@ class Detection implements IMimeTypeDetector { /** @var string */ private $defaultConfigDir; - /** - * @param IURLGenerator $urlGenerator - * @param ILogger $logger - * @param string $customConfigDir - * @param string $defaultConfigDir - */ public function __construct(IURLGenerator $urlGenerator, - ILogger $logger, + LoggerInterface $logger, string $customConfigDir, string $defaultConfigDir) { $this->urlGenerator = $urlGenerator; diff --git a/lib/private/Files/Utils/Scanner.php b/lib/private/Files/Utils/Scanner.php index 5b633617608..dc220bc710d 100644 --- a/lib/private/Files/Utils/Scanner.php +++ b/lib/private/Files/Utils/Scanner.php @@ -48,7 +48,7 @@ use OCP\Files\NotFoundException; use OCP\Files\Storage\IStorage; use OCP\Files\StorageNotAvailableException; use OCP\IDBConnection; -use OCP\ILogger; +use Psr\Log\LoggerInterface; /** * Class Scanner @@ -71,8 +71,7 @@ class Scanner extends PublicEmitter { /** @var IEventDispatcher */ private $dispatcher; - /** @var ILogger */ - protected $logger; + protected LoggerInterface $logger; /** * Whether to use a DB transaction @@ -92,9 +91,8 @@ class Scanner extends PublicEmitter { * @param string $user * @param IDBConnection|null $db * @param IEventDispatcher $dispatcher - * @param ILogger $logger */ - public function __construct($user, $db, IEventDispatcher $dispatcher, ILogger $logger) { + public function __construct($user, $db, IEventDispatcher $dispatcher, LoggerInterface $logger) { $this->user = $user; $this->db = $db; $this->dispatcher = $dispatcher; @@ -263,8 +261,7 @@ class Scanner extends PublicEmitter { } $propagator->commitBatch(); } catch (StorageNotAvailableException $e) { - $this->logger->error('Storage ' . $storage->getId() . ' not available'); - $this->logger->logException($e); + $this->logger->error('Storage ' . $storage->getId() . ' not available', ['exception' => $e]); $this->emit('\OC\Files\Utils\Scanner', 'StorageNotAvailable', [$e]); } if ($this->useTransaction) { |