From fe05882628aed7e4959ae7c363ba2909a75533cc Mon Sep 17 00:00:00 2001 From: Ferdinand Thiessen Date: Sat, 14 Sep 2024 20:41:33 +0200 Subject: [PATCH 1/9] chore!: Remove `OC\AppFramework\Logger` Signed-off-by: Ferdinand Thiessen --- .../DependencyInjection/DIContainer.php | 4 - lib/private/AppFramework/Logger.php | 108 ------------------ 2 files changed, 112 deletions(-) delete mode 100644 lib/private/AppFramework/Logger.php diff --git a/lib/private/AppFramework/DependencyInjection/DIContainer.php b/lib/private/AppFramework/DependencyInjection/DIContainer.php index a96e050c0e643..0b87fea127ee4 100644 --- a/lib/private/AppFramework/DependencyInjection/DIContainer.php +++ b/lib/private/AppFramework/DependencyInjection/DIContainer.php @@ -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; @@ -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(); diff --git a/lib/private/AppFramework/Logger.php b/lib/private/AppFramework/Logger.php deleted file mode 100644 index 4ae4e6cae347e..0000000000000 --- a/lib/private/AppFramework/Logger.php +++ /dev/null @@ -1,108 +0,0 @@ -logger = $logger; - $this->appName = $appName; - } - - private function extendContext(array $context): array { - if (!isset($context['app'])) { - $context['app'] = $this->appName; - } - - return $context; - } - - /** - * @deprecated - */ - public function emergency(string $message, array $context = []) { - $this->logger->emergency($message, $this->extendContext($context)); - } - - /** - * @deprecated - */ - public function alert(string $message, array $context = []) { - $this->logger->alert($message, $this->extendContext($context)); - } - - /** - * @deprecated - */ - public function critical(string $message, array $context = []) { - $this->logger->critical($message, $this->extendContext($context)); - } - - /** - * @deprecated - */ - public function error(string $message, array $context = []) { - $this->logger->emergency($message, $this->extendContext($context)); - } - - /** - * @deprecated - */ - public function warning(string $message, array $context = []) { - $this->logger->warning($message, $this->extendContext($context)); - } - - /** - * @deprecated - */ - public function notice(string $message, array $context = []) { - $this->logger->notice($message, $this->extendContext($context)); - } - - /** - * @deprecated - */ - public function info(string $message, array $context = []) { - $this->logger->info($message, $this->extendContext($context)); - } - - /** - * @deprecated - */ - public function debug(string $message, array $context = []) { - $this->logger->debug($message, $this->extendContext($context)); - } - - /** - * @deprecated - */ - public function log(int $level, string $message, array $context = []) { - $this->logger->log($level, $message, $this->extendContext($context)); - } - - /** - * @deprecated - */ - public function logException(\Throwable $exception, array $context = []) { - $this->logger->logException($exception, $this->extendContext($context)); - } -} From 44c724874919240ccd524abce623068317e8d66e Mon Sep 17 00:00:00 2001 From: Ferdinand Thiessen Date: Sun, 15 Sep 2024 01:24:05 +0200 Subject: [PATCH 2/9] refactor(Collaboration): Use non-deprecated methods MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Ferdinand Thiessen Co-authored-by: Côme Chilliet <91878298+come-nc@users.noreply.github.com> Signed-off-by: Ferdinand Thiessen --- .../Collaboration/AutoComplete/Manager.php | 24 +++++++++++++------ .../Collaboration/Resources/ManagerTest.php | 11 ++++----- 2 files changed, 22 insertions(+), 13 deletions(-) diff --git a/lib/private/Collaboration/AutoComplete/Manager.php b/lib/private/Collaboration/AutoComplete/Manager.php index 382b918853517..c4dd4093e6921 100644 --- a/lib/private/Collaboration/AutoComplete/Manager.php +++ b/lib/private/Collaboration/AutoComplete/Manager.php @@ -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[] */ @@ -17,7 +19,8 @@ class Manager implements IManager { protected array $sorterInstances = []; public function __construct( - private IServerContainer $container, + private ContainerInterface $container, + private LoggerInterface $logger, ) { } @@ -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 ]); } @@ -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; } diff --git a/tests/lib/Collaboration/Resources/ManagerTest.php b/tests/lib/Collaboration/Resources/ManagerTest.php index 4ca88da86780f..0e4e42458e2be 100644 --- a/tests/lib/Collaboration/Resources/ManagerTest.php +++ b/tests/lib/Collaboration/Resources/ManagerTest.php @@ -12,16 +12,15 @@ use OCP\Collaboration\Resources\IManager; use OCP\Collaboration\Resources\IProviderManager; use OCP\IDBConnection; +use PHPUnit\Framework\MockObject\MockObject; use Psr\Log\LoggerInterface; use Test\TestCase; class ManagerTest extends TestCase { - /** @var LoggerInterface */ - protected $logger; - /** @var IProviderManager */ - protected $providerManager; - /** @var IManager */ - protected $manager; + + protected LoggerInterface&MockObject $logger; + protected IProviderManager&MockObject $providerManager; + protected IManager $manager; protected function setUp(): void { parent::setUp(); From 7ae62cfe47675e7b5fca4c2a7f07dbf45d7172b8 Mon Sep 17 00:00:00 2001 From: Ferdinand Thiessen Date: Sun, 15 Sep 2024 01:29:14 +0200 Subject: [PATCH 3/9] refactor(ProviderFactory): Remove usage of ILogger and use non-deprecated stuff Signed-off-by: Ferdinand Thiessen --- lib/private/Share20/ProviderFactory.php | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/lib/private/Share20/ProviderFactory.php b/lib/private/Share20/ProviderFactory.php index e1a2c9a537538..7335c863df050 100644 --- a/lib/private/Share20/ProviderFactory.php +++ b/lib/private/Share20/ProviderFactory.php @@ -38,8 +38,6 @@ * @package OC\Share20 */ class ProviderFactory implements IProviderFactory { - /** @var IServerContainer */ - private $serverContainer; /** @var DefaultShareProvider */ private $defaultProvider = null; /** @var FederatedShareProvider */ @@ -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 { @@ -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), ); @@ -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( @@ -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) @@ -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() ); } From 69abd8851b943e646f03ce654b1dae324381fdf0 Mon Sep 17 00:00:00 2001 From: Ferdinand Thiessen Date: Sun, 15 Sep 2024 01:34:47 +0200 Subject: [PATCH 4/9] refactor(OC_App): Remove ILogger usage Signed-off-by: Ferdinand Thiessen --- lib/private/legacy/OC_App.php | 28 +++++++++++++++------------- 1 file changed, 15 insertions(+), 13 deletions(-) diff --git a/lib/private/legacy/OC_App.php b/lib/private/legacy/OC_App.php index 0756f274a1192..e5c2c34294dad 100644 --- a/lib/private/legacy/OC_App.php +++ b/lib/private/legacy/OC_App.php @@ -388,7 +388,7 @@ public static function getCurrentApp(): string { * @deprecated 20.0.0 Please register your alternative login option using the registerAlternativeLogin() on the RegistrationContext in your Application class implementing the OCP\Authentication\IAlternativeLogin interface */ public static function registerLogIn(array $entry) { - \OC::$server->getLogger()->debug('OC_App::registerLogIn() is deprecated, please register your alternative login option using the registerAlternativeLogin() on the RegistrationContext in your Application class implementing the OCP\Authentication\IAlternativeLogin interface'); + \OCP\Server::get(LoggerInterface::class)->debug('OC_App::registerLogIn() is deprecated, please register your alternative login option using the registerAlternativeLogin() on the RegistrationContext in your Application class implementing the OCP\Authentication\IAlternativeLogin interface'); self::$altLogin[] = $entry; } @@ -401,7 +401,7 @@ public static function getAlternativeLogIns(): array { foreach ($bootstrapCoordinator->getRegistrationContext()->getAlternativeLogins() as $registration) { if (!in_array(IAlternativeLogin::class, class_implements($registration->getService()), true)) { - \OC::$server->getLogger()->error('Alternative login option {option} does not implement {interface} and is therefore ignored.', [ + \OCP\Server::get(LoggerInterface::class)->error('Alternative login option {option} does not implement {interface} and is therefore ignored.', [ 'option' => $registration->getService(), 'interface' => IAlternativeLogin::class, 'app' => $registration->getAppId(), @@ -413,11 +413,12 @@ public static function getAlternativeLogIns(): array { /** @var IAlternativeLogin $provider */ $provider = \OCP\Server::get($registration->getService()); } catch (ContainerExceptionInterface $e) { - \OC::$server->getLogger()->logException($e, [ - 'message' => 'Alternative login option {option} can not be initialised.', - 'option' => $registration->getService(), - 'app' => $registration->getAppId(), - ]); + \OCP\Server::get(LoggerInterface::class)->error('Alternative login option {option} can not be initialized.', + [ + 'exception' => $e, + 'option' => $registration->getService(), + 'app' => $registration->getAppId(), + ]); } try { @@ -429,11 +430,12 @@ public static function getAlternativeLogIns(): array { 'class' => $provider->getClass(), ]; } catch (Throwable $e) { - \OC::$server->getLogger()->logException($e, [ - 'message' => 'Alternative login option {option} had an error while loading.', - 'option' => $registration->getService(), - 'app' => $registration->getAppId(), - ]); + \OCP\Server::get(LoggerInterface::class)->error('Alternative login option {option} had an error while loading.', + [ + 'exception' => $e, + 'option' => $registration->getService(), + 'app' => $registration->getAppId(), + ]); } } @@ -667,7 +669,7 @@ public static function updateApp(string $appId): bool { } if (is_file($appPath . '/appinfo/database.xml')) { - \OC::$server->getLogger()->error('The appinfo/database.xml file is not longer supported. Used in ' . $appId); + \OCP\Server::get(LoggerInterface::class)->error('The appinfo/database.xml file is not longer supported. Used in ' . $appId); return false; } From 0d31976690578c27cdd9de71e27e9a6084ead3a4 Mon Sep 17 00:00:00 2001 From: Ferdinand Thiessen Date: Sun, 15 Sep 2024 01:37:11 +0200 Subject: [PATCH 5/9] refactor(OC_Hook): Remove deprecated ILogger Signed-off-by: Ferdinand Thiessen --- lib/private/legacy/OC_Hook.php | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/lib/private/legacy/OC_Hook.php b/lib/private/legacy/OC_Hook.php index 5c36a25389531..e472b10549803 100644 --- a/lib/private/legacy/OC_Hook.php +++ b/lib/private/legacy/OC_Hook.php @@ -5,6 +5,9 @@ * SPDX-FileCopyrightText: 2016 ownCloud, Inc. * SPDX-License-Identifier: AGPL-3.0-only */ + +use Psr\Log\LoggerInterface; + class OC_Hook { public static $thrownExceptions = []; @@ -82,7 +85,7 @@ public static function emit($signalClass, $signalName, $params = []) { call_user_func([ $i['class'], $i['name'] ], $params); } catch (Exception $e) { self::$thrownExceptions[] = $e; - \OC::$server->getLogger()->logException($e); + \OCP\Server::get(LoggerInterface::class)->error($e->getMessage(), ['exception' => $e]); if ($e instanceof \OCP\HintException) { throw $e; } From 8b79283c6bcd045c16a869fc79dce1e2f582601f Mon Sep 17 00:00:00 2001 From: Ferdinand Thiessen Date: Sun, 15 Sep 2024 01:45:29 +0200 Subject: [PATCH 6/9] refactor(OC_Util): Remove deprecated ILogger Signed-off-by: Ferdinand Thiessen --- lib/private/legacy/OC_Util.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/private/legacy/OC_Util.php b/lib/private/legacy/OC_Util.php index 84bb0b645d5d0..e152feb639e03 100644 --- a/lib/private/legacy/OC_Util.php +++ b/lib/private/legacy/OC_Util.php @@ -175,7 +175,7 @@ public static function copySkeleton($userId, \OCP\Files\Folder $userDirectory) { * @return void */ public static function copyr($source, \OCP\Files\Folder $target) { - $logger = \OC::$server->getLogger(); + $logger = \OCP\Server::get(LoggerInterface::class); // Verify if folder exists $dir = opendir($source); @@ -1015,7 +1015,7 @@ public static function normalizeUnicode($value) { $normalizedValue = Normalizer::normalize($value); if ($normalizedValue === null || $normalizedValue === false) { - \OC::$server->getLogger()->warning('normalizing failed for "' . $value . '"', ['app' => 'core']); + \OCP\Server::get(LoggerInterface::class)->warning('normalizing failed for "' . $value . '"', ['app' => 'core']); return $value; } From 74923d174bcf5ec4f9484de9f51bf55141b5918b Mon Sep 17 00:00:00 2001 From: Ferdinand Thiessen Date: Sun, 15 Sep 2024 01:45:51 +0200 Subject: [PATCH 7/9] refactor(OC_Files): Remove deprecated ILogger Signed-off-by: Ferdinand Thiessen --- lib/private/legacy/OC_Files.php | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/lib/private/legacy/OC_Files.php b/lib/private/legacy/OC_Files.php index 8e23d70c69060..126472e306144 100644 --- a/lib/private/legacy/OC_Files.php +++ b/lib/private/legacy/OC_Files.php @@ -7,12 +7,14 @@ */ use bantu\IniGetWrapper\IniGetWrapper; use OC\Files\View; +use OC\HintException; use OC\Streamer; use OCP\EventDispatcher\IEventDispatcher; use OCP\Files\Events\BeforeDirectFileDownloadEvent; use OCP\Files\Events\BeforeZipCreatedEvent; use OCP\Files\IRootFolder; use OCP\Lock\ILockingProvider; +use Psr\Log\LoggerInterface; /** * Class for file server access @@ -165,7 +167,7 @@ public static function get($dir, $files, $params = null) { $fileTime = $file->getMTime(); } else { // File is not a file? … - \OC::$server->getLogger()->debug( + \OCP\Server::get(LoggerInterface::class)->debug( 'File given, but no Node available. Name {file}', [ 'app' => 'files', 'file' => $file ] ); @@ -186,25 +188,25 @@ public static function get($dir, $files, $params = null) { self::unlockAllTheFiles($dir, $files, $getType, $view, $filename); } catch (\OCP\Lock\LockedException $ex) { self::unlockAllTheFiles($dir, $files, $getType, $view, $filename); - OC::$server->getLogger()->logException($ex); + \OCP\Server::get(LoggerInterface::class)->error('File is currently busy', ['exception' => $ex]); $l = \OC::$server->getL10N('lib'); - $hint = method_exists($ex, 'getHint') ? $ex->getHint() : ''; + $hint = $ex instanceof HintException ? $ex->getHint() : ''; \OC_Template::printErrorPage($l->t('File is currently busy, please try again later'), $hint, 200); } catch (\OCP\Files\ForbiddenException $ex) { self::unlockAllTheFiles($dir, $files, $getType, $view, $filename); - OC::$server->getLogger()->logException($ex); + \OCP\Server::get(LoggerInterface::class)->error('Cannot download file', ['exception' => $ex]); $l = \OC::$server->getL10N('lib'); \OC_Template::printErrorPage($l->t('Cannot download file'), $ex->getMessage(), 200); } catch (\OCP\Files\ConnectionLostException $ex) { self::unlockAllTheFiles($dir, $files, $getType, $view, $filename); - OC::$server->getLogger()->logException($ex, ['level' => \OCP\ILogger::DEBUG]); + \OCP\Server::get(LoggerInterface::class)->debug('Connection lost', ['exception' => $ex]); /* We do not print anything here, the connection is already closed */ die(); } catch (\Exception $ex) { self::unlockAllTheFiles($dir, $files, $getType, $view, $filename); - OC::$server->getLogger()->logException($ex); + \OCP\Server::get(LoggerInterface::class)->error('Cannot download file', ['exception' => $ex]); $l = \OC::$server->getL10N('lib'); - $hint = method_exists($ex, 'getHint') ? $ex->getHint() : ''; + $hint = $ex instanceof HintException ? $ex->getHint() : ''; if ($event && $event->getErrorMessage() !== null) { $hint .= ' ' . $event->getErrorMessage(); } From f1dfd6ba71b476366694fdcdfb75f85e90535203 Mon Sep 17 00:00:00 2001 From: Ferdinand Thiessen Date: Sun, 15 Sep 2024 01:46:10 +0200 Subject: [PATCH 8/9] refactor(OC_Template): Remove deprecated ILogger Signed-off-by: Ferdinand Thiessen --- lib/private/legacy/OC_Template.php | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/lib/private/legacy/OC_Template.php b/lib/private/legacy/OC_Template.php index 422709cec7d7c..47803041cb55c 100644 --- a/lib/private/legacy/OC_Template.php +++ b/lib/private/legacy/OC_Template.php @@ -9,6 +9,7 @@ use OCP\AppFramework\Http\Events\BeforeTemplateRenderedEvent; use OCP\AppFramework\Http\TemplateResponse; use OCP\EventDispatcher\IEventDispatcher; +use Psr\Log\LoggerInterface; require_once __DIR__.'/template/functions.php'; @@ -242,10 +243,10 @@ public static function printErrorPage($error_msg, $hint = '', $statusCode = 500) \OC::$server->get(IEventDispatcher::class)->dispatchTyped($event); print($response->render()); } catch (\Throwable $e1) { - $logger = \OC::$server->getLogger(); - $logger->logException($e1, [ + $logger = \OCP\Server::get(LoggerInterface::class); + $logger->error('Rendering themed error page failed. Falling back to un-themed error page.', [ 'app' => 'core', - 'message' => 'Rendering themed error page failed. Falling back to unthemed error page.' + 'exception' => $e1, ]); try { @@ -256,9 +257,9 @@ public static function printErrorPage($error_msg, $hint = '', $statusCode = 500) } catch (\Exception $e2) { // If nothing else works, fall back to plain text error page $logger->error("$error_msg $hint", ['app' => 'core']); - $logger->logException($e2, [ + $logger->error('Rendering un-themed error page failed. Falling back to plain text error page.', [ 'app' => 'core', - 'message' => 'Rendering unthemed error page failed. Falling back to plain text error page.' + 'exception' => $e2, ]); header('Content-Type: text/plain; charset=utf-8'); @@ -296,9 +297,9 @@ public static function printExceptionErrorPage($exception, $statusCode = 503) { $content->printPage(); } catch (\Exception $e) { try { - $logger = \OC::$server->getLogger(); - $logger->logException($exception, ['app' => 'core']); - $logger->logException($e, ['app' => 'core']); + $logger = \OCP\Server::get(LoggerInterface::class); + $logger->error($exception->getMessage(), ['app' => 'core', 'exception' => $exception]); + $logger->error($e->getMessage(), ['app' => 'core', 'exception' => $e]); } catch (Throwable $e) { // no way to log it properly - but to avoid a white page of death we send some output self::printPlainErrorPage($e, $debug); From 5cce140701638aabac9ca692433b45517b741161 Mon Sep 17 00:00:00 2001 From: Ferdinand Thiessen Date: Thu, 19 Sep 2024 00:37:06 +0200 Subject: [PATCH 9/9] chore: Remove deprecated `ILogger` logging functions Signed-off-by: Ferdinand Thiessen --- apps/user_ldap/lib/LDAPProvider.php | 5 +- lib/composer/composer/autoload_classmap.php | 1 - lib/composer/composer/autoload_static.php | 1 - lib/private/Log/LogFactory.php | 6 - lib/private/Server.php | 13 +- lib/public/ILogger.php | 135 +------------------- lib/public/IServerContainer.php | 9 -- 7 files changed, 9 insertions(+), 161 deletions(-) diff --git a/apps/user_ldap/lib/LDAPProvider.php b/apps/user_ldap/lib/LDAPProvider.php index a6634382fa1f4..3b1568d174832 100644 --- a/apps/user_ldap/lib/LDAPProvider.php +++ b/apps/user_ldap/lib/LDAPProvider.php @@ -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; @@ -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; diff --git a/lib/composer/composer/autoload_classmap.php b/lib/composer/composer/autoload_classmap.php index 578395a45b405..82964a6e6c72c 100644 --- a/lib/composer/composer/autoload_classmap.php +++ b/lib/composer/composer/autoload_classmap.php @@ -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', diff --git a/lib/composer/composer/autoload_static.php b/lib/composer/composer/autoload_static.php index 2e507ec7a5fbf..d83229c7426c4 100644 --- a/lib/composer/composer/autoload_static.php +++ b/lib/composer/composer/autoload_static.php @@ -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', diff --git a/lib/private/Log/LogFactory.php b/lib/private/Log/LogFactory.php index a5a7290bd9ce6..612d98c97466e 100644 --- a/lib/private/Log/LogFactory.php +++ b/lib/private/Log/LogFactory.php @@ -7,7 +7,6 @@ use OC\Log; use OC\SystemConfig; -use OCP\ILogger; use OCP\IServerContainer; use OCP\Log\ILogFactory; use OCP\Log\IWriter; @@ -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), diff --git a/lib/private/Server.php b/lib/private/Server.php index f48cc0d0a48db..943b4fc6997c5 100644 --- a/lib/private/Server.php +++ b/lib/private/Server.php @@ -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; @@ -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)); @@ -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); @@ -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 diff --git a/lib/public/ILogger.php b/lib/public/ILogger.php index 0716dae07d6d5..54f9ffeca9a3f 100644 --- a/lib/public/ILogger.php +++ b/lib/public/ILogger.php @@ -9,157 +9,32 @@ namespace OCP; /** - * Interface ILogger - * @since 7.0.0 + * Nextcloud logging levels. + * For historical reasons the logging levels are provided as interface constants. * - * This logger interface follows the design guidelines of PSR-3 - * https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-3-logger-interface.md#3-psrlogloggerinterface - * @deprecated 20.0.0 use the PSR-3 logger \Psr\Log\LoggerInterface + * @since 7.0.0 + * @since 20.0.0 deprecated logging methods in favor of \Psr\Log\LoggerInterface + * @since 31.0.0 removed deprecated logging methods - the interface is kept for Nextcloud log levels */ interface ILogger { /** * @since 14.0.0 - * @deprecated 20.0.0 */ public const DEBUG = 0; /** * @since 14.0.0 - * @deprecated 20.0.0 */ public const INFO = 1; /** * @since 14.0.0 - * @deprecated 20.0.0 */ public const WARN = 2; /** * @since 14.0.0 - * @deprecated 20.0.0 */ public const ERROR = 3; /** * @since 14.0.0 - * @deprecated 20.0.0 */ public const FATAL = 4; - - /** - * System is unusable. - * - * @param string $message - * @param array $context - * @return null - * @since 7.0.0 - * @deprecated 20.0.0 use \Psr\Log\LoggerInterface::emergency - */ - public function emergency(string $message, array $context = []); - - /** - * Action must be taken immediately. - * - * @param string $message - * @param array $context - * @return null - * @since 7.0.0 - * @deprecated 20.0.0 use \Psr\Log\LoggerInterface::alert - */ - public function alert(string $message, array $context = []); - - /** - * Critical conditions. - * - * @param string $message - * @param array $context - * @return null - * @since 7.0.0 - * @deprecated 20.0.0 use \Psr\Log\LoggerInterface::critical - */ - public function critical(string $message, array $context = []); - - /** - * Runtime errors that do not require immediate action but should typically - * be logged and monitored. - * - * @param string $message - * @param array $context - * @return null - * @since 7.0.0 - * @deprecated 20.0.0 use \Psr\Log\LoggerInterface::error - */ - public function error(string $message, array $context = []); - - /** - * Exceptional occurrences that are not errors. - * - * @param string $message - * @param array $context - * @return null - * @since 7.0.0 - * @deprecated 20.0.0 use \Psr\Log\LoggerInterface::warning - */ - public function warning(string $message, array $context = []); - - /** - * Normal but significant events. - * - * @param string $message - * @param array $context - * @return null - * @since 7.0.0 - * @deprecated 20.0.0 use \Psr\Log\LoggerInterface::notice - */ - public function notice(string $message, array $context = []); - - /** - * Interesting events. - * - * @param string $message - * @param array $context - * @return null - * @since 7.0.0 - * @deprecated 20.0.0 use \Psr\Log\LoggerInterface::info - */ - public function info(string $message, array $context = []); - - /** - * Detailed debug information. - * - * @param string $message - * @param array $context - * @return null - * @since 7.0.0 - * @deprecated 20.0.0 use \Psr\Log\LoggerInterface::debug - */ - public function debug(string $message, array $context = []); - - /** - * Logs with an arbitrary level. - * - * @param int $level - * @param string $message - * @param array $context - * @return mixed - * @since 7.0.0 - * @deprecated 20.0.0 use \Psr\Log\LoggerInterface::log - */ - public function log(int $level, string $message, array $context = []); - - /** - * Logs an exception very detailed - * An additional message can we written to the log by adding it to the - * context. - * - * - * $logger->logException($ex, [ - * 'message' => 'Exception during background job execution' - * ]); - * - * - * @param \Exception|\Throwable $exception - * @param array $context - * @return void - * @since 8.2.0 - * @deprecated 20.0.0 use the `exception` entry in the context of any method in \Psr\Log\LoggerInterface - */ - public function logException(\Throwable $exception, array $context = []); } diff --git a/lib/public/IServerContainer.php b/lib/public/IServerContainer.php index 027dfcb77c48c..82da8779a66e9 100644 --- a/lib/public/IServerContainer.php +++ b/lib/public/IServerContainer.php @@ -316,15 +316,6 @@ public function getAvatarManager(); */ public function getJobList(); - /** - * Returns a logger instance - * - * @return \OCP\ILogger - * @since 8.0.0 - * @deprecated 20.0.0 have it injected or fetch it through \Psr\Container\ContainerInterface::get - */ - public function getLogger(); - /** * returns a log factory instance *