diff options
author | Joas Schilling <213943+nickvergessen@users.noreply.github.com> | 2024-09-19 10:58:38 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-09-19 10:58:38 +0200 |
commit | 086b11f8fb5c86518b89e365b7d26a0a9c9eccc1 (patch) | |
tree | b20a787046576187cef6d0ed83648d389d9f1785 /lib | |
parent | a0cb795f043e27a1ef2f438f655efe690311a9b2 (diff) | |
parent | 5cce140701638aabac9ca692433b45517b741161 (diff) | |
download | nextcloud-server-086b11f8fb5c86518b89e365b7d26a0a9c9eccc1.tar.gz nextcloud-server-086b11f8fb5c86518b89e365b7d26a0a9c9eccc1.zip |
Merge pull request #47978 from nextcloud/chore/remove-ilogger
chore!: Remove `ILogger` and its friends
Diffstat (limited to 'lib')
-rw-r--r-- | lib/composer/composer/autoload_classmap.php | 1 | ||||
-rw-r--r-- | lib/composer/composer/autoload_static.php | 1 | ||||
-rw-r--r-- | lib/private/AppFramework/DependencyInjection/DIContainer.php | 4 | ||||
-rw-r--r-- | lib/private/AppFramework/Logger.php | 108 | ||||
-rw-r--r-- | lib/private/Collaboration/AutoComplete/Manager.php | 24 | ||||
-rw-r--r-- | lib/private/Log/LogFactory.php | 6 | ||||
-rw-r--r-- | lib/private/Server.php | 13 | ||||
-rw-r--r-- | lib/private/Share20/ProviderFactory.php | 19 | ||||
-rw-r--r-- | lib/private/legacy/OC_App.php | 28 | ||||
-rw-r--r-- | lib/private/legacy/OC_Files.php | 16 | ||||
-rw-r--r-- | lib/private/legacy/OC_Hook.php | 5 | ||||
-rw-r--r-- | lib/private/legacy/OC_Template.php | 17 | ||||
-rw-r--r-- | lib/private/legacy/OC_Util.php | 4 | ||||
-rw-r--r-- | lib/public/ILogger.php | 135 | ||||
-rw-r--r-- | lib/public/IServerContainer.php | 9 |
15 files changed, 71 insertions, 319 deletions
diff --git a/lib/composer/composer/autoload_classmap.php b/lib/composer/composer/autoload_classmap.php index 578395a45b4..82964a6e6c7 100644 --- a/lib/composer/composer/autoload_classmap.php +++ b/lib/composer/composer/autoload_classmap.php @@ -931,7 +931,6 @@ return array( '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 2e507ec7a5f..d83229c7426 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/AppFramework/DependencyInjection/DIContainer.php b/lib/private/AppFramework/DependencyInjection/DIContainer.php index a96e050c0e6..0b87fea127e 100644 --- a/lib/private/AppFramework/DependencyInjection/DIContainer.php +++ b/lib/private/AppFramework/DependencyInjection/DIContainer.php @@ -39,7 +39,6 @@ use OCP\IDBConnection; 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 @@ class DIContainer extends SimpleContainer implements IAppContainer { $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 4ae4e6cae34..00000000000 --- a/lib/private/AppFramework/Logger.php +++ /dev/null @@ -1,108 +0,0 @@ -<?php - -declare(strict_types=1); - -/** - * SPDX-FileCopyrightText: 2018 Nextcloud GmbH and Nextcloud contributors - * SPDX-License-Identifier: AGPL-3.0-or-later - */ -namespace OC\AppFramework; - -use OCP\ILogger; - -/** - * @deprecated - */ -class Logger implements ILogger { - /** @var ILogger */ - private $logger; - - /** @var string */ - private $appName; - - /** - * @deprecated - */ - public function __construct(ILogger $logger, string $appName) { - $this->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)); - } -} diff --git a/lib/private/Collaboration/AutoComplete/Manager.php b/lib/private/Collaboration/AutoComplete/Manager.php index 382b9188535..c4dd4093e69 100644 --- a/lib/private/Collaboration/AutoComplete/Manager.php +++ b/lib/private/Collaboration/AutoComplete/Manager.php @@ -7,7 +7,9 @@ namespace OC\Collaboration\AutoComplete; 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 @@ class Manager implements IManager { 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 @@ class Manager implements IManager { 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/lib/private/Log/LogFactory.php b/lib/private/Log/LogFactory.php index a5a7290bd9c..612d98c9746 100644 --- a/lib/private/Log/LogFactory.php +++ b/lib/private/Log/LogFactory.php @@ -7,7 +7,6 @@ namespace OC\Log; use OC\Log; use OC\SystemConfig; -use OCP\ILogger; use OCP\IServerContainer; use OCP\Log\ILogFactory; use OCP\Log\IWriter; @@ -33,11 +32,6 @@ class LogFactory implements ILogFactory { }; } - 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 f48cc0d0a48..943b4fc6997 100644 --- a/lib/private/Server.php +++ b/lib/private/Server.php @@ -177,7 +177,6 @@ use OCP\IEventSourceFactory; 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 @@ class Server extends ServerContainer implements IServerContainer { $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 @@ class Server extends ServerContainer implements IServerContainer { 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); @@ -1657,16 +1656,6 @@ class Server extends ServerContainer implements IServerContainer { } /** - * Returns a logger instance - * - * @return ILogger - * @deprecated 20.0.0 - */ - public function getLogger() { - return $this->get(ILogger::class); - } - - /** * @return ILogFactory * @throws \OCP\AppFramework\QueryException * @deprecated 20.0.0 diff --git a/lib/private/Share20/ProviderFactory.php b/lib/private/Share20/ProviderFactory.php index e1a2c9a5375..7335c863df0 100644 --- a/lib/private/Share20/ProviderFactory.php +++ b/lib/private/Share20/ProviderFactory.php @@ -38,8 +38,6 @@ use Psr\Log\LoggerInterface; * @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 @@ class ProviderFactory implements IProviderFactory { $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 @@ class ProviderFactory implements IProviderFactory { $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 @@ class ProviderFactory implements IProviderFactory { $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 @@ class ProviderFactory implements IProviderFactory { $this->serverContainer->getUserManager(), $this->serverContainer->get(IRootFolder::class), $this->serverContainer->getL10N('circles'), - $this->serverContainer->getLogger(), + $this->serverContainer->get(LoggerInterface::class), $this->serverContainer->getURLGenerator() ); } diff --git a/lib/private/legacy/OC_App.php b/lib/private/legacy/OC_App.php index 0756f274a11..e5c2c34294d 100644 --- a/lib/private/legacy/OC_App.php +++ b/lib/private/legacy/OC_App.php @@ -388,7 +388,7 @@ class OC_App { * @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 @@ class OC_App { 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 @@ class OC_App { /** @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 @@ class OC_App { '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 @@ class OC_App { } 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; } diff --git a/lib/private/legacy/OC_Files.php b/lib/private/legacy/OC_Files.php index 8e23d70c690..126472e3061 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 @@ class OC_Files { $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 @@ class OC_Files { 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(); } diff --git a/lib/private/legacy/OC_Hook.php b/lib/private/legacy/OC_Hook.php index 5c36a253895..e472b105498 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 @@ class OC_Hook { 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; } diff --git a/lib/private/legacy/OC_Template.php b/lib/private/legacy/OC_Template.php index 422709cec7d..47803041cb5 100644 --- a/lib/private/legacy/OC_Template.php +++ b/lib/private/legacy/OC_Template.php @@ -9,6 +9,7 @@ use OC\TemplateLayout; 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 @@ class OC_Template extends \OC\Template\Base { \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 @@ class OC_Template extends \OC\Template\Base { } 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 @@ class OC_Template extends \OC\Template\Base { $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); diff --git a/lib/private/legacy/OC_Util.php b/lib/private/legacy/OC_Util.php index 84bb0b645d5..e152feb639e 100644 --- a/lib/private/legacy/OC_Util.php +++ b/lib/private/legacy/OC_Util.php @@ -175,7 +175,7 @@ class OC_Util { * @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 @@ class OC_Util { $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; } diff --git a/lib/public/ILogger.php b/lib/public/ILogger.php index 0716dae07d6..54f9ffeca9a 100644 --- a/lib/public/ILogger.php +++ b/lib/public/ILogger.php @@ -9,157 +9,32 @@ declare(strict_types=1); 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. - * - * <code> - * $logger->logException($ex, [ - * 'message' => 'Exception during background job execution' - * ]); - * </code> - * - * @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 027dfcb77c4..82da8779a66 100644 --- a/lib/public/IServerContainer.php +++ b/lib/public/IServerContainer.php @@ -317,15 +317,6 @@ interface IServerContainer extends ContainerInterface, IContainer { 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 * * @return ILogFactory |