Skip to content

Commit

Permalink
Merge pull request #47978 from nextcloud/chore/remove-ilogger
Browse files Browse the repository at this point in the history
chore!: Remove `ILogger` and its friends
  • Loading branch information
nickvergessen authored Sep 19, 2024
2 parents a0cb795 + 5cce140 commit 086b11f
Show file tree
Hide file tree
Showing 17 changed files with 79 additions and 327 deletions.
5 changes: 3 additions & 2 deletions apps/user_ldap/lib/LDAPProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,10 @@
use OCP\IServerContainer;
use OCP\LDAP\IDeletionFlagSupport;
use OCP\LDAP\ILDAPProvider;
use Psr\Log\LoggerInterface;

/**
* LDAP provider for pulic access to the LDAP backend.
* LDAP provider for public access to the LDAP backend.
*/
class LDAPProvider implements ILDAPProvider, IDeletionFlagSupport {
private $userBackend;
Expand All @@ -30,7 +31,7 @@ class LDAPProvider implements ILDAPProvider, IDeletionFlagSupport {
* @throws \Exception if user_ldap app was not enabled
*/
public function __construct(IServerContainer $serverContainer, Helper $helper, DeletedUsersIndex $deletedUsersIndex) {
$this->logger = $serverContainer->getLogger();
$this->logger = $serverContainer->get(LoggerInterface::class);
$this->helper = $helper;
$this->deletedUsersIndex = $deletedUsersIndex;
$userBackendFound = false;
Expand Down
1 change: 0 additions & 1 deletion lib/composer/composer/autoload_classmap.php
Original file line number Diff line number Diff line change
Expand Up @@ -931,7 +931,6 @@
'OC\\AppFramework\\Http\\Output' => $baseDir . '/lib/private/AppFramework/Http/Output.php',
'OC\\AppFramework\\Http\\Request' => $baseDir . '/lib/private/AppFramework/Http/Request.php',
'OC\\AppFramework\\Http\\RequestId' => $baseDir . '/lib/private/AppFramework/Http/RequestId.php',
'OC\\AppFramework\\Logger' => $baseDir . '/lib/private/AppFramework/Logger.php',
'OC\\AppFramework\\Middleware\\AdditionalScriptsMiddleware' => $baseDir . '/lib/private/AppFramework/Middleware/AdditionalScriptsMiddleware.php',
'OC\\AppFramework\\Middleware\\CompressionMiddleware' => $baseDir . '/lib/private/AppFramework/Middleware/CompressionMiddleware.php',
'OC\\AppFramework\\Middleware\\MiddlewareDispatcher' => $baseDir . '/lib/private/AppFramework/Middleware/MiddlewareDispatcher.php',
Expand Down
1 change: 0 additions & 1 deletion lib/composer/composer/autoload_static.php
Original file line number Diff line number Diff line change
Expand Up @@ -964,7 +964,6 @@ class ComposerStaticInit749170dad3f5e7f9ca158f5a9f04f6a2
'OC\\AppFramework\\Http\\Output' => __DIR__ . '/../../..' . '/lib/private/AppFramework/Http/Output.php',
'OC\\AppFramework\\Http\\Request' => __DIR__ . '/../../..' . '/lib/private/AppFramework/Http/Request.php',
'OC\\AppFramework\\Http\\RequestId' => __DIR__ . '/../../..' . '/lib/private/AppFramework/Http/RequestId.php',
'OC\\AppFramework\\Logger' => __DIR__ . '/../../..' . '/lib/private/AppFramework/Logger.php',
'OC\\AppFramework\\Middleware\\AdditionalScriptsMiddleware' => __DIR__ . '/../../..' . '/lib/private/AppFramework/Middleware/AdditionalScriptsMiddleware.php',
'OC\\AppFramework\\Middleware\\CompressionMiddleware' => __DIR__ . '/../../..' . '/lib/private/AppFramework/Middleware/CompressionMiddleware.php',
'OC\\AppFramework\\Middleware\\MiddlewareDispatcher' => __DIR__ . '/../../..' . '/lib/private/AppFramework/Middleware/MiddlewareDispatcher.php',
Expand Down
4 changes: 0 additions & 4 deletions lib/private/AppFramework/DependencyInjection/DIContainer.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@
use OCP\IGroupManager;
use OCP\IInitialStateService;
use OCP\IL10N;
use OCP\ILogger;
use OCP\INavigationManager;
use OCP\IRequest;
use OCP\IServerContainer;
Expand Down Expand Up @@ -120,9 +119,6 @@ public function __construct(string $appName, array $urlParams = [], ?ServerConta
$c->get('AppName')
);
});
$this->registerService(ILogger::class, function (ContainerInterface $c) {
return new OC\AppFramework\Logger($this->server->query(ILogger::class), $c->get('AppName'));
});

$this->registerService(IServerContainer::class, function () {
return $this->getServer();
Expand Down
108 changes: 0 additions & 108 deletions lib/private/AppFramework/Logger.php

This file was deleted.

24 changes: 17 additions & 7 deletions lib/private/Collaboration/AutoComplete/Manager.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@

use OCP\Collaboration\AutoComplete\IManager;
use OCP\Collaboration\AutoComplete\ISorter;
use OCP\IServerContainer;
use Psr\Container\ContainerExceptionInterface;
use Psr\Container\ContainerInterface;
use Psr\Log\LoggerInterface;

class Manager implements IManager {
/** @var string[] */
Expand All @@ -17,7 +19,8 @@ class Manager implements IManager {
protected array $sorterInstances = [];

public function __construct(
private IServerContainer $container,
private ContainerInterface $container,
private LoggerInterface $logger,
) {
}

Expand All @@ -27,7 +30,7 @@ public function runSorters(array $sorters, array &$sortArray, array $context): v
if (isset($sorterInstances[$sorter])) {
$sorterInstances[$sorter]->sort($sortArray, $context);
} else {
$this->container->getLogger()->warning('No sorter for ID "{id}", skipping', [
$this->logger->warning('No sorter for ID "{id}", skipping', [
'app' => 'core', 'id' => $sorter
]);
}
Expand All @@ -41,16 +44,23 @@ public function registerSorter($className): void {
protected function getSorters(): array {
if (count($this->sorterInstances) === 0) {
foreach ($this->sorters as $sorter) {
/** @var ISorter $instance */
$instance = $this->container->resolve($sorter);
try {
$instance = $this->container->get($sorter);
} catch (ContainerExceptionInterface) {
$this->logger->notice(
'Skipping not registered sorter. Class name: {class}',
['app' => 'core', 'class' => $sorter],
);
continue;
}
if (!$instance instanceof ISorter) {
$this->container->getLogger()->notice('Skipping sorter which is not an instance of ISorter. Class name: {class}',
$this->logger->notice('Skipping sorter which is not an instance of ISorter. Class name: {class}',
['app' => 'core', 'class' => $sorter]);
continue;
}
$sorterId = trim($instance->getId());
if (trim($sorterId) === '') {
$this->container->getLogger()->notice('Skipping sorter with empty ID. Class name: {class}',
$this->logger->notice('Skipping sorter with empty ID. Class name: {class}',
['app' => 'core', 'class' => $sorter]);
continue;
}
Expand Down
6 changes: 0 additions & 6 deletions lib/private/Log/LogFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@

use OC\Log;
use OC\SystemConfig;
use OCP\ILogger;
use OCP\IServerContainer;
use OCP\Log\ILogFactory;
use OCP\Log\IWriter;
Expand All @@ -33,11 +32,6 @@ public function get(string $type):IWriter {
};
}

public function getCustomLogger(string $path): ILogger {
$log = $this->buildLogFile($path);
return new Log($log, $this->systemConfig);
}

protected function createNewLogger(string $type, string $tag, string $path): IWriter {
return match (strtolower($type)) {
'errorlog' => new Errorlog($this->systemConfig, $tag),
Expand Down
13 changes: 1 addition & 12 deletions lib/private/Server.php
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,6 @@
use OCP\IGroupManager;
use OCP\IInitialStateService;
use OCP\IL10N;
use OCP\ILogger;
use OCP\INavigationManager;
use OCP\IPhoneNumberUtil;
use OCP\IPreview;
Expand Down Expand Up @@ -680,6 +679,7 @@ public function __construct($webRoot, \OC\Config $config) {
$this->registerAlias(\OCP\Support\Subscription\IRegistry::class, \OC\Support\Subscription\Registry::class);
$this->registerAlias(\OCP\Support\Subscription\IAssertion::class, \OC\Support\Subscription\Assertion::class);

/** Only used by the PsrLoggerAdapter should not be used by apps */
$this->registerService(\OC\Log::class, function (Server $c) {
$logType = $c->get(AllConfig::class)->getSystemValue('log_type', 'file');
$factory = new LogFactory($c, $this->get(SystemConfig::class));
Expand All @@ -688,7 +688,6 @@ public function __construct($webRoot, \OC\Config $config) {

return new Log($logger, $this->get(SystemConfig::class), crashReporters: $registry);
});
$this->registerAlias(ILogger::class, \OC\Log::class);
// PSR-3 logger
$this->registerAlias(LoggerInterface::class, PsrLoggerAdapter::class);

Expand Down Expand Up @@ -1656,16 +1655,6 @@ public function getJobList() {
return $this->get(IJobList::class);
}

/**
* Returns a logger instance
*
* @return ILogger
* @deprecated 20.0.0
*/
public function getLogger() {
return $this->get(ILogger::class);
}

/**
* @return ILogFactory
* @throws \OCP\AppFramework\QueryException
Expand Down
19 changes: 9 additions & 10 deletions lib/private/Share20/ProviderFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,6 @@
* @package OC\Share20
*/
class ProviderFactory implements IProviderFactory {
/** @var IServerContainer */
private $serverContainer;
/** @var DefaultShareProvider */
private $defaultProvider = null;
/** @var FederatedShareProvider */
Expand All @@ -62,8 +60,9 @@ class ProviderFactory implements IProviderFactory {
*
* @param IServerContainer $serverContainer
*/
public function __construct(IServerContainer $serverContainer) {
$this->serverContainer = $serverContainer;
public function __construct(
private IServerContainer $serverContainer,
) {
}

public function registerProvider(string $shareProviderClass): void {
Expand All @@ -83,10 +82,10 @@ protected function defaultShareProvider() {
$this->serverContainer->getGroupManager(),
$this->serverContainer->get(IRootFolder::class),
$this->serverContainer->get(IMailer::class),
$this->serverContainer->query(Defaults::class),
$this->serverContainer->get(Defaults::class),
$this->serverContainer->get(IFactory::class),
$this->serverContainer->getURLGenerator(),
$this->serverContainer->query(ITimeFactory::class),
$this->serverContainer->get(ITimeFactory::class),
$this->serverContainer->get(LoggerInterface::class),
$this->serverContainer->get(IManager::class),
);
Expand Down Expand Up @@ -122,11 +121,11 @@ protected function federatedShareProvider() {
$notifications = new Notifications(
$addressHandler,
$this->serverContainer->get(IClientService::class),
$this->serverContainer->query(\OCP\OCS\IDiscoveryService::class),
$this->serverContainer->get(\OCP\OCS\IDiscoveryService::class),
$this->serverContainer->getJobList(),
\OC::$server->getCloudFederationProviderManager(),
\OC::$server->get(ICloudFederationFactory::class),
$this->serverContainer->query(IEventDispatcher::class),
$this->serverContainer->get(IEventDispatcher::class),
$this->serverContainer->get(LoggerInterface::class),
);
$tokenHandler = new TokenHandler(
Expand Down Expand Up @@ -181,7 +180,7 @@ protected function getShareByMailProvider() {
$this->serverContainer->getURLGenerator(),
$this->serverContainer->getActivityManager(),
$settingsManager,
$this->serverContainer->query(Defaults::class),
$this->serverContainer->get(Defaults::class),
$this->serverContainer->get(IHasher::class),
$this->serverContainer->get(IEventDispatcher::class),
$this->serverContainer->get(IManager::class)
Expand Down Expand Up @@ -218,7 +217,7 @@ protected function getShareByCircleProvider() {
$this->serverContainer->getUserManager(),
$this->serverContainer->get(IRootFolder::class),
$this->serverContainer->getL10N('circles'),
$this->serverContainer->getLogger(),
$this->serverContainer->get(LoggerInterface::class),
$this->serverContainer->getURLGenerator()
);
}
Expand Down
Loading

0 comments on commit 086b11f

Please sign in to comment.