Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Migrate from ILogger to LoggerInterface in lib/private #31609

Merged
merged 10 commits into from
Mar 29, 2022
8 changes: 4 additions & 4 deletions apps/dav/tests/unit/Comments/RootCollectionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ class RootCollectionTest extends \Test\TestCase {
protected $commentsManager;
/** @var \OCP\IUserManager|\PHPUnit\Framework\MockObject\MockObject */
protected $userManager;
/** @var \OCP\ILogger|\PHPUnit\Framework\MockObject\MockObject */
/** @var LoggerInterface|\PHPUnit\Framework\MockObject\MockObject */
protected $logger;
/** @var \OCA\DAV\Comments\RootCollection */
protected $collection;
Expand All @@ -70,14 +70,14 @@ protected function setUp(): void {
$this->userSession = $this->getMockBuilder(IUserSession::class)
->disableOriginalConstructor()
->getMock();
$this->logger = $this->getMockBuilder(ILogger::class)
$this->logger = $this->getMockBuilder(LoggerInterface::class)
->disableOriginalConstructor()
->getMock();
$this->dispatcher = new SymfonyAdapter(
new EventDispatcher(
new \Symfony\Component\EventDispatcher\EventDispatcher(),
\OC::$server,
$this->createMock(LoggerInterface::class)
$this->logger
),
$this->logger
);
Expand All @@ -87,7 +87,7 @@ protected function setUp(): void {
$this->userManager,
$this->userSession,
$this->dispatcher,
$this->logger
$this->createMock(ILogger::class)
);
}

Expand Down
15 changes: 4 additions & 11 deletions apps/files/lib/BackgroundJob/ScanFiles.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
use OCP\EventDispatcher\IEventDispatcher;
use OCP\IConfig;
use OCP\IDBConnection;
use OCP\ILogger;
use Psr\Log\LoggerInterface;

/**
* Class ScanFiles is a background job used to run the file scanner over the user
Expand All @@ -42,23 +42,16 @@ class ScanFiles extends \OC\BackgroundJob\TimedJob {
private $config;
/** @var IEventDispatcher */
private $dispatcher;
/** @var ILogger */
private $logger;
private LoggerInterface $logger;
private $connection;

/** Amount of users that should get scanned per execution */
public const USERS_PER_SESSION = 500;

/**
* @param IConfig $config
* @param IEventDispatcher $dispatcher
* @param ILogger $logger
* @param IDBConnection $connection
*/
public function __construct(
IConfig $config,
IEventDispatcher $dispatcher,
ILogger $logger,
LoggerInterface $logger,
IDBConnection $connection
) {
// Run once per 10 minutes
Expand All @@ -83,7 +76,7 @@ protected function runScanner(string $user) {
);
$scanner->backgroundScan('');
} catch (\Exception $e) {
$this->logger->logException($e, ['app' => 'files']);
$this->logger->error($e->getMessage(), ['exception' => $e, 'app' => 'files']);
}
\OC_Util::tearDownFS();
}
Expand Down
3 changes: 2 additions & 1 deletion apps/files/lib/Command/Scan.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
use OCP\Files\NotFoundException;
use OCP\Files\StorageNotAvailableException;
use OCP\IUserManager;
use Psr\Log\LoggerInterface;
use Symfony\Component\Console\Helper\Table;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
Expand Down Expand Up @@ -111,7 +112,7 @@ protected function scanFiles($user, $path, OutputInterface $output, $backgroundS
$user,
new ConnectionAdapter($connection),
\OC::$server->query(IEventDispatcher::class),
\OC::$server->getLogger()
\OC::$server->get(LoggerInterface::class)
);

# check on each file/folder if there was a user interrupt (ctrl-c) and throw an exception
Expand Down
3 changes: 2 additions & 1 deletion apps/files/lib/Command/ScanAppData.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
use OCP\Files\NotFoundException;
use OCP\Files\StorageNotAvailableException;
use OCP\IConfig;
use Psr\Log\LoggerInterface;
use Symfony\Component\Console\Helper\Table;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
Expand Down Expand Up @@ -95,7 +96,7 @@ protected function scanFiles(OutputInterface $output, string $folder): int {
null,
new ConnectionAdapter($connection),
\OC::$server->query(IEventDispatcher::class),
\OC::$server->getLogger()
\OC::$server->get(LoggerInterface::class)
);

# check on each file/folder if there was a user interrupt (ctrl-c) and throw an exception
Expand Down
4 changes: 2 additions & 2 deletions apps/files/tests/BackgroundJob/ScanFilesTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@
use OCA\Files\BackgroundJob\ScanFiles;
use OCP\EventDispatcher\IEventDispatcher;
use OCP\IConfig;
use OCP\ILogger;
use OCP\IUser;
use Psr\Log\LoggerInterface;
use Test\TestCase;
use Test\Traits\MountProviderTrait;
use Test\Traits\UserTrait;
Expand All @@ -54,7 +54,7 @@ protected function setUp(): void {

$config = $this->createMock(IConfig::class);
$dispatcher = $this->createMock(IEventDispatcher::class);
$logger = $this->createMock(ILogger::class);
$logger = $this->createMock(LoggerInterface::class);
$connection = \OC::$server->getDatabaseConnection();
$this->mountCache = \OC::$server->getUserMountCache();

Expand Down
40 changes: 20 additions & 20 deletions apps/files_external/lib/Lib/Storage/Swift.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,9 @@
use OC\Files\ObjectStore\SwiftFactory;
use OCP\Files\IMimeTypeDetector;
use OCP\Files\StorageBadConfigException;
use OCP\ILogger;
use OpenStack\Common\Error\BadResponseError;
use OpenStack\ObjectStore\v1\Models\StorageObject;
use Psr\Log\LoggerInterface;

class Swift extends \OC\Files\Storage\Common {
/** @var SwiftFactory */
Expand Down Expand Up @@ -138,8 +138,8 @@ private function fetchObject(string $path) {
} catch (BadResponseError $e) {
// Expected response is "404 Not Found", so only log if it isn't
if ($e->getResponse()->getStatusCode() !== 404) {
\OC::$server->getLogger()->logException($e, [
'level' => ILogger::ERROR,
\OC::$server->get(LoggerInterface::class)->error($e->getMessage(), [
'exception' => $e,
'app' => 'files_external',
]);
}
Expand Down Expand Up @@ -204,7 +204,7 @@ public function __construct($params) {
$this->connectionFactory = new SwiftFactory(
\OC::$server->getMemCacheFactory()->createDistributed('swift/'),
$this->params,
\OC::$server->getLogger()
\OC::$server->get(LoggerInterface::class)
);
$this->objectStore = new \OC\Files\ObjectStore\Swift($this->params, $this->connectionFactory);
$this->bucket = $params['bucket'];
Expand Down Expand Up @@ -232,8 +232,8 @@ public function mkdir($path) {
// with all properties
$this->objectCache->remove($path);
} catch (BadResponseError $e) {
\OC::$server->getLogger()->logException($e, [
'level' => ILogger::ERROR,
\OC::$server->get(LoggerInterface::class)->error($e->getMessage(), [
'exception' => $e,
'app' => 'files_external',
]);
return false;
Expand Down Expand Up @@ -276,8 +276,8 @@ public function rmdir($path) {
$this->objectStore->deleteObject($path . '/');
$this->objectCache->remove($path . '/');
} catch (BadResponseError $e) {
\OC::$server->getLogger()->logException($e, [
'level' => ILogger::ERROR,
\OC::$server->get(LoggerInterface::class)->error($e->getMessage(), [
'exception' => $e,
'app' => 'files_external',
]);
return false;
Expand Down Expand Up @@ -314,8 +314,8 @@ public function opendir($path) {

return IteratorDirectory::wrap($files);
} catch (\Exception $e) {
\OC::$server->getLogger()->logException($e, [
'level' => ILogger::ERROR,
\OC::$server->get(LoggerInterface::class)->error($e->getMessage(), [
'exception' => $e,
'app' => 'files_external',
]);
return false;
Expand All @@ -337,8 +337,8 @@ public function stat($path) {
return false;
}
} catch (BadResponseError $e) {
\OC::$server->getLogger()->logException($e, [
'level' => ILogger::ERROR,
\OC::$server->get(LoggerInterface::class)->error($e->getMessage(), [
'exception' => $e,
'app' => 'files_external',
]);
return false;
Expand Down Expand Up @@ -391,8 +391,8 @@ public function unlink($path) {
$this->objectCache->remove($path . '/');
} catch (BadResponseError $e) {
if ($e->getResponse()->getStatusCode() !== 404) {
\OC::$server->getLogger()->logException($e, [
'level' => ILogger::ERROR,
\OC::$server->get(LoggerInterface::class)->error($e->getMessage(), [
'exception' => $e,
'app' => 'files_external',
]);
throw $e;
Expand All @@ -415,8 +415,8 @@ public function fopen($path, $mode) {
try {
return $this->objectStore->readObject($path);
} catch (BadResponseError $e) {
\OC::$server->getLogger()->logException($e, [
'level' => ILogger::ERROR,
\OC::$server->get(LoggerInterface::class)->error($e->getMessage(), [
'exception' => $e,
'app' => 'files_external',
]);
return false;
Expand Down Expand Up @@ -502,8 +502,8 @@ public function copy($path1, $path2) {
$this->objectCache->remove($path2);
$this->objectCache->remove($path2 . '/');
} catch (BadResponseError $e) {
\OC::$server->getLogger()->logException($e, [
'level' => ILogger::ERROR,
\OC::$server->get(LoggerInterface::class)->error($e->getMessage(), [
'exception' => $e,
'app' => 'files_external',
]);
return false;
Expand All @@ -518,8 +518,8 @@ public function copy($path1, $path2) {
$this->objectCache->remove($path2);
$this->objectCache->remove($path2 . '/');
} catch (BadResponseError $e) {
\OC::$server->getLogger()->logException($e, [
'level' => ILogger::ERROR,
\OC::$server->get(LoggerInterface::class)->error($e->getMessage(), [
'exception' => $e,
'app' => 'files_external',
]);
return false;
Expand Down
4 changes: 2 additions & 2 deletions apps/files_sharing/tests/CapabilitiesTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@
use OCP\IConfig;
use OCP\IGroupManager;
use OCP\IL10N;
use OCP\ILogger;
use OCP\IURLGenerator;
use OCP\IUserManager;
use OCP\IUserSession;
Expand All @@ -46,6 +45,7 @@
use OCP\Security\IHasher;
use OCP\Security\ISecureRandom;
use OCP\Share\IProviderFactory;
use Psr\Log\LoggerInterface;
use Symfony\Component\EventDispatcher\EventDispatcherInterface;

/**
Expand Down Expand Up @@ -79,7 +79,7 @@ private function getResults(array $map) {
$config = $this->getMockBuilder(IConfig::class)->disableOriginalConstructor()->getMock();
$config->method('getAppValue')->willReturnMap($map);
$shareManager = new Manager(
$this->createMock(ILogger::class),
$this->createMock(LoggerInterface::class),
$config,
$this->createMock(ISecureRandom::class),
$this->createMock(IHasher::class),
Expand Down
22 changes: 14 additions & 8 deletions apps/files_trashbin/lib/Trashbin.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@
use OCP\Files\NotPermittedException;
use OCP\Lock\ILockingProvider;
use OCP\Lock\LockedException;
use Psr\Log\LoggerInterface;

class Trashbin {

Expand Down Expand Up @@ -227,7 +228,7 @@ private static function copyFilesToUser($sourcePath, $owner, $targetPath, $user,
->setValue('user', $query->createNamedParameter($user));
$result = $query->executeStatement();
if (!$result) {
\OC::$server->getLogger()->error('trash bin database couldn\'t be updated for the files owner', ['app' => 'files_trashbin']);
\OC::$server->get(LoggerInterface::class)->error('trash bin database couldn\'t be updated for the files owner', ['app' => 'files_trashbin']);
}
}
}
Expand Down Expand Up @@ -326,7 +327,7 @@ public static function move2trash($file_path, $ownerOnly = false) {
if ($trashStorage->file_exists($trashInternalPath)) {
$trashStorage->unlink($trashInternalPath);
}
\OC::$server->getLogger()->error('Couldn\'t move ' . $file_path . ' to the trash bin', ['app' => 'files_trashbin']);
\OC::$server->get(LoggerInterface::class)->error('Couldn\'t move ' . $file_path . ' to the trash bin', ['app' => 'files_trashbin']);
}

if ($sourceStorage->file_exists($sourceInternalPath)) { // failed to delete the original file, abort
Expand Down Expand Up @@ -354,7 +355,7 @@ public static function move2trash($file_path, $ownerOnly = false) {
->setValue('user', $query->createNamedParameter($owner));
$result = $query->executeStatement();
if (!$result) {
\OC::$server->getLogger()->error('trash bin database couldn\'t be updated', ['app' => 'files_trashbin']);
\OC::$server->get(LoggerInterface::class)->error('trash bin database couldn\'t be updated', ['app' => 'files_trashbin']);
}
\OCP\Util::emitHook('\OCA\Files_Trashbin\Trashbin', 'post_moveToTrash', ['filePath' => Filesystem::normalizePath($file_path),
'trashPath' => Filesystem::normalizePath($filename . '.d' . $timestamp)]);
Expand Down Expand Up @@ -470,7 +471,7 @@ public static function restore($file, $filename, $timestamp) {
if ($timestamp) {
$location = self::getLocation($user, $filename, $timestamp);
if ($location === false) {
\OC::$server->getLogger()->error('trash bin database inconsistent! ($user: ' . $user . ' $filename: ' . $filename . ', $timestamp: ' . $timestamp . ')', ['app' => 'files_trashbin']);
\OC::$server->get(LoggerInterface::class)->error('trash bin database inconsistent! ($user: ' . $user . ' $filename: ' . $filename . ', $timestamp: ' . $timestamp . ')', ['app' => 'files_trashbin']);
} else {
// if location no longer exists, restore file in the root directory
if ($location !== '/' &&
Expand Down Expand Up @@ -870,7 +871,7 @@ protected static function deleteFiles($files, $user, $availableSpace) {
foreach ($files as $file) {
if ($availableSpace < 0 && $expiration->isExpired($file['mtime'], true)) {
$tmp = self::delete($file['name'], $user, $file['mtime']);
\OC::$server->getLogger()->info('remove "' . $file['name'] . '" (' . $tmp . 'B) to meet the limit of trash bin size (50% of available quota)', ['app' => 'files_trashbin']);
\OC::$server->get(LoggerInterface::class)->info('remove "' . $file['name'] . '" (' . $tmp . 'B) to meet the limit of trash bin size (50% of available quota)', ['app' => 'files_trashbin']);
$availableSpace += $tmp;
$size += $tmp;
} else {
Expand Down Expand Up @@ -901,9 +902,14 @@ public static function deleteExpiredFiles($files, $user) {
$size += self::delete($filename, $user, $timestamp);
$count++;
} catch (\OCP\Files\NotPermittedException $e) {
\OC::$server->getLogger()->logException($e, ['app' => 'files_trashbin', 'level' => \OCP\ILogger::WARN, 'message' => 'Removing "' . $filename . '" from trashbin failed.']);
\OC::$server->get(LoggerInterface::class)->warning('Removing "' . $filename . '" from trashbin failed.',
[
'exception' => $e,
'app' => 'files_trashbin',
]
);
}
\OC::$server->getLogger()->info(
\OC::$server->get(LoggerInterface::class)->info(
'Remove "' . $filename . '" from trashbin because it exceeds max retention obligation term.',
['app' => 'files_trashbin']
);
Expand Down Expand Up @@ -999,7 +1005,7 @@ private static function getVersionsFromTrash($filename, $timestamp, $user) {
$query = new CacheQueryBuilder(
\OC::$server->getDatabaseConnection(),
\OC::$server->getSystemConfig(),
\OC::$server->getLogger()
\OC::$server->get(LoggerInterface::class)
);
$normalizedParentPath = ltrim(Filesystem::normalizePath(dirname('files_trashbin/versions/'. $filename)), '/');
$parentId = $cache->getId($normalizedParentPath);
Expand Down
13 changes: 6 additions & 7 deletions apps/testing/lib/Locking/FakeDBLockingProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@

use OCP\AppFramework\Utility\ITimeFactory;
use OCP\IDBConnection;
use OCP\ILogger;
use Psr\Log\LoggerInterface;

class FakeDBLockingProvider extends \OC\Lock\DBLockingProvider {
// Lock for 10 hours just to be sure
Expand All @@ -37,12 +37,11 @@ class FakeDBLockingProvider extends \OC\Lock\DBLockingProvider {
*/
protected $db;

/**
* @param \OCP\IDBConnection $connection
* @param \OCP\ILogger $logger
* @param \OCP\AppFramework\Utility\ITimeFactory $timeFactory
*/
public function __construct(IDBConnection $connection, ILogger $logger, ITimeFactory $timeFactory) {
public function __construct(
IDBConnection $connection,
LoggerInterface $logger,
ITimeFactory $timeFactory
) {
parent::__construct($connection, $logger, $timeFactory);
$this->db = $connection;
}
Expand Down
Loading