diff options
Diffstat (limited to 'lib')
23 files changed, 127 insertions, 199 deletions
diff --git a/lib/private/App/AppManager.php b/lib/private/App/AppManager.php index 7063878429a..a00a93aa847 100644 --- a/lib/private/App/AppManager.php +++ b/lib/private/App/AppManager.php @@ -46,9 +46,9 @@ use OCP\ICacheFactory; use OCP\IConfig; use OCP\IGroup; use OCP\IGroupManager; -use OCP\ILogger; use OCP\IUser; use OCP\IUserSession; +use Psr\Log\LoggerInterface; use Symfony\Component\EventDispatcher\EventDispatcherInterface; class AppManager implements IAppManager { @@ -83,7 +83,7 @@ class AppManager implements IAppManager { /** @var EventDispatcherInterface */ private $dispatcher; - /** @var ILogger */ + /** @var LoggerInterface */ private $logger; /** @var string[] $appId => $enabled */ @@ -104,21 +104,13 @@ class AppManager implements IAppManager { /** @var array */ private $autoDisabledApps = []; - /** - * @param IUserSession $userSession - * @param IConfig $config - * @param AppConfig $appConfig - * @param IGroupManager $groupManager - * @param ICacheFactory $memCacheFactory - * @param EventDispatcherInterface $dispatcher - */ public function __construct(IUserSession $userSession, IConfig $config, AppConfig $appConfig, IGroupManager $groupManager, ICacheFactory $memCacheFactory, EventDispatcherInterface $dispatcher, - ILogger $logger) { + LoggerInterface $logger) { $this->userSession = $userSession; $this->config = $config; $this->appConfig = $appConfig; @@ -249,7 +241,7 @@ class AppManager implements IAppManager { if (!is_array($groupIds)) { $jsonError = json_last_error(); - $this->logger->warning('AppManger::checkAppForUser - can\'t decode group IDs: ' . print_r($enabled, true) . ' - json error code: ' . $jsonError, ['app' => 'lib']); + $this->logger->warning('AppManger::checkAppForUser - can\'t decode group IDs: ' . print_r($enabled, true) . ' - json error code: ' . $jsonError); return false; } @@ -282,7 +274,7 @@ class AppManager implements IAppManager { if (!is_array($groupIds)) { $jsonError = json_last_error(); - $this->logger->warning('AppManger::checkAppForUser - can\'t decode group IDs: ' . print_r($enabled, true) . ' - json error code: ' . $jsonError, ['app' => 'lib']); + $this->logger->warning('AppManger::checkAppForUser - can\'t decode group IDs: ' . print_r($enabled, true) . ' - json error code: ' . $jsonError); return false; } diff --git a/lib/private/App/AppStore/Fetcher/AppFetcher.php b/lib/private/App/AppStore/Fetcher/AppFetcher.php index 416e55463cf..cd6b005c0d1 100644 --- a/lib/private/App/AppStore/Fetcher/AppFetcher.php +++ b/lib/private/App/AppStore/Fetcher/AppFetcher.php @@ -37,6 +37,7 @@ use OCP\AppFramework\Utility\ITimeFactory; use OCP\Http\Client\IClientService; use OCP\IConfig; use OCP\ILogger; +use Psr\Log\LoggerInterface; class AppFetcher extends Fetcher { @@ -46,20 +47,12 @@ class AppFetcher extends Fetcher { /** @var bool */ private $ignoreMaxVersion; - /** - * @param Factory $appDataFactory - * @param IClientService $clientService - * @param ITimeFactory $timeFactory - * @param IConfig $config - * @param CompareVersion $compareVersion - * @param ILogger $logger - */ public function __construct(Factory $appDataFactory, IClientService $clientService, ITimeFactory $timeFactory, IConfig $config, CompareVersion $compareVersion, - ILogger $logger) { + LoggerInterface $logger) { parent::__construct( $appDataFactory, $clientService, @@ -86,7 +79,7 @@ class AppFetcher extends Fetcher { protected function fetch($ETag, $content, $allowUnstable = false) { /** @var mixed[] $response */ $response = parent::fetch($ETag, $content); - + if (empty($response)) { return []; } @@ -134,7 +127,9 @@ class AppFetcher extends Fetcher { $releases[] = $release; } } catch (\InvalidArgumentException $e) { - $this->logger->logException($e, ['app' => 'appstoreFetcher', 'level' => ILogger::WARN]); + $this->logger->warning($e->getMessage(), [ + 'exception' => $e, + ]); } } } diff --git a/lib/private/App/AppStore/Fetcher/CategoryFetcher.php b/lib/private/App/AppStore/Fetcher/CategoryFetcher.php index e34fbee8c58..896444a6640 100644 --- a/lib/private/App/AppStore/Fetcher/CategoryFetcher.php +++ b/lib/private/App/AppStore/Fetcher/CategoryFetcher.php @@ -31,21 +31,14 @@ use OC\Files\AppData\Factory; use OCP\AppFramework\Utility\ITimeFactory; use OCP\Http\Client\IClientService; use OCP\IConfig; -use OCP\ILogger; +use Psr\Log\LoggerInterface; class CategoryFetcher extends Fetcher { - /** - * @param Factory $appDataFactory - * @param IClientService $clientService - * @param ITimeFactory $timeFactory - * @param IConfig $config - * @param ILogger $logger - */ public function __construct(Factory $appDataFactory, IClientService $clientService, ITimeFactory $timeFactory, IConfig $config, - ILogger $logger) { + LoggerInterface $logger) { parent::__construct( $appDataFactory, $clientService, diff --git a/lib/private/App/AppStore/Fetcher/Fetcher.php b/lib/private/App/AppStore/Fetcher/Fetcher.php index c5d83fcb1df..24c2fce00f5 100644 --- a/lib/private/App/AppStore/Fetcher/Fetcher.php +++ b/lib/private/App/AppStore/Fetcher/Fetcher.php @@ -39,7 +39,7 @@ use OCP\Files\IAppData; use OCP\Files\NotFoundException; use OCP\Http\Client\IClientService; use OCP\IConfig; -use OCP\ILogger; +use Psr\Log\LoggerInterface; abstract class Fetcher { public const INVALIDATE_AFTER_SECONDS = 3600; @@ -53,7 +53,7 @@ abstract class Fetcher { protected $timeFactory; /** @var IConfig */ protected $config; - /** @var Ilogger */ + /** @var LoggerInterface */ protected $logger; /** @var string */ protected $fileName; @@ -64,18 +64,11 @@ abstract class Fetcher { /** @var string */ protected $channel; - /** - * @param Factory $appDataFactory - * @param IClientService $clientService - * @param ITimeFactory $timeFactory - * @param IConfig $config - * @param ILogger $logger - */ public function __construct(Factory $appDataFactory, IClientService $clientService, ITimeFactory $timeFactory, IConfig $config, - ILogger $logger) { + LoggerInterface $logger) { $this->appData = $appDataFactory->get('appstore'); $this->clientService = $clientService; $this->timeFactory = $timeFactory; @@ -202,7 +195,10 @@ abstract class Fetcher { $this->logger->warning('Could not connect to appstore: ' . $e->getMessage(), ['app' => 'appstoreFetcher']); return []; } catch (\Exception $e) { - $this->logger->logException($e, ['app' => 'appstoreFetcher', 'level' => ILogger::WARN]); + $this->logger->warning($e->getMessage(), [ + 'exception' => $e, + 'app' => 'appstoreFetcher', + ]); return []; } } diff --git a/lib/private/AppFramework/Bootstrap/Coordinator.php b/lib/private/AppFramework/Bootstrap/Coordinator.php index 06a17e5242b..627618f04fa 100644 --- a/lib/private/AppFramework/Bootstrap/Coordinator.php +++ b/lib/private/AppFramework/Bootstrap/Coordinator.php @@ -36,8 +36,8 @@ use OCP\AppFramework\Bootstrap\IBootstrap; use OCP\AppFramework\QueryException; use OCP\Dashboard\IManager; use OCP\EventDispatcher\IEventDispatcher; -use OCP\ILogger; use OCP\IServerContainer; +use Psr\Log\LoggerInterface; use Throwable; use function class_exists; use function class_implements; @@ -57,7 +57,7 @@ class Coordinator { /** @var IEventDispatcher */ private $eventDispatcher; - /** @var ILogger */ + /** @var LoggerInterface */ private $logger; /** @var RegistrationContext|null */ @@ -70,7 +70,7 @@ class Coordinator { Registry $registry, IManager $dashboardManager, IEventDispatcher $eventListener, - ILogger $logger) { + LoggerInterface $logger) { $this->serverContainer = $container; $this->registry = $registry; $this->dashboardManager = $dashboardManager; @@ -124,9 +124,8 @@ class Coordinator { try { $application->register($this->registrationContext->for($appId)); } catch (Throwable $e) { - $this->logger->logException($e, [ - 'message' => 'Error during app service registration: ' . $e->getMessage(), - 'level' => ILogger::FATAL, + $this->logger->emergency('Error during app service registration: ' . $e->getMessage(), [ + 'exception' => $e, ]); } } diff --git a/lib/private/AppFramework/Bootstrap/RegistrationContext.php b/lib/private/AppFramework/Bootstrap/RegistrationContext.php index d056c088a9f..0859e606b7e 100644 --- a/lib/private/AppFramework/Bootstrap/RegistrationContext.php +++ b/lib/private/AppFramework/Bootstrap/RegistrationContext.php @@ -43,10 +43,10 @@ use OCP\Dashboard\IWidget; use OCP\EventDispatcher\IEventDispatcher; use OCP\Files\Template\ICustomTemplateProvider; use OCP\Http\WellKnown\IHandler; -use OCP\ILogger; use OCP\Notification\INotifier; use OCP\Search\IProvider; use OCP\Support\CrashReport\IReporter; +use Psr\Log\LoggerInterface; use Throwable; use function array_shift; @@ -97,10 +97,10 @@ class RegistrationContext { /** @var ServiceRegistration<\OCP\Authentication\TwoFactorAuth\IProvider>[] */ private $twoFactorProviders = []; - /** @var ILogger */ + /** @var LoggerInterface */ private $logger; - public function __construct(ILogger $logger) { + public function __construct(LoggerInterface $logger) { $this->logger = $logger; } @@ -313,9 +313,8 @@ class RegistrationContext { ->registerCapability($registration->getService()); } catch (Throwable $e) { $appId = $registration->getAppId(); - $this->logger->logException($e, [ - 'message' => "Error during capability registration of $appId: " . $e->getMessage(), - 'level' => ILogger::ERROR, + $this->logger->error("Error during capability registration of $appId: " . $e->getMessage(), [ + 'exception' => $e, ]); } } @@ -330,9 +329,8 @@ class RegistrationContext { $registry->registerLazy($registration->getService()); } catch (Throwable $e) { $appId = $registration->getAppId(); - $this->logger->logException($e, [ - 'message' => "Error during crash reporter registration of $appId: " . $e->getMessage(), - 'level' => ILogger::ERROR, + $this->logger->error("Error during crash reporter registration of $appId: " . $e->getMessage(), [ + 'exception' => $e, ]); } } @@ -347,9 +345,8 @@ class RegistrationContext { $dashboardManager->lazyRegisterWidget($panel->getService()); } catch (Throwable $e) { $appId = $panel->getAppId(); - $this->logger->logException($e, [ - 'message' => "Error during dashboard registration of $appId: " . $e->getMessage(), - 'level' => ILogger::ERROR, + $this->logger->error("Error during dashboard registration of $appId: " . $e->getMessage(), [ + 'exception' => $e, ]); } } @@ -365,9 +362,8 @@ class RegistrationContext { ); } catch (Throwable $e) { $appId = $registration->getAppId(); - $this->logger->logException($e, [ - 'message' => "Error during event listener registration of $appId: " . $e->getMessage(), - 'level' => ILogger::ERROR, + $this->logger->error("Error during event listener registration of $appId: " . $e->getMessage(), [ + 'exception' => $e, ]); } } @@ -391,9 +387,8 @@ class RegistrationContext { ); } catch (Throwable $e) { $appId = $registration->getAppId(); - $this->logger->logException($e, [ - 'message' => "Error during service registration of $appId: " . $e->getMessage(), - 'level' => ILogger::ERROR, + $this->logger->error("Error during service registration of $appId: " . $e->getMessage(), [ + 'exception' => $e, ]); } } @@ -408,9 +403,8 @@ class RegistrationContext { ); } catch (Throwable $e) { $appId = $registration->getAppId(); - $this->logger->logException($e, [ - 'message' => "Error during service alias registration of $appId: " . $e->getMessage(), - 'level' => ILogger::ERROR, + $this->logger->error("Error during service alias registration of $appId: " . $e->getMessage(), [ + 'exception' => $e, ]); } } @@ -425,9 +419,8 @@ class RegistrationContext { ); } catch (Throwable $e) { $appId = $registration->getAppId(); - $this->logger->logException($e, [ - 'message' => "Error during service alias registration of $appId: " . $e->getMessage(), - 'level' => ILogger::ERROR, + $this->logger->error("Error during service alias registration of $appId: " . $e->getMessage(), [ + 'exception' => $e, ]); } } @@ -444,9 +437,8 @@ class RegistrationContext { ->registerMiddleWare($middleware->getService()); } catch (Throwable $e) { $appId = $middleware->getAppId(); - $this->logger->logException($e, [ - 'message' => "Error during capability registration of $appId: " . $e->getMessage(), - 'level' => ILogger::ERROR, + $this->logger->error("Error during capability registration of $appId: " . $e->getMessage(), [ + 'exception' => $e, ]); } } diff --git a/lib/private/AppFramework/Middleware/Security/SecurityMiddleware.php b/lib/private/AppFramework/Middleware/Security/SecurityMiddleware.php index 76665f8998f..9fa696154ff 100644 --- a/lib/private/AppFramework/Middleware/Security/SecurityMiddleware.php +++ b/lib/private/AppFramework/Middleware/Security/SecurityMiddleware.php @@ -55,11 +55,11 @@ use OCP\AppFramework\Http\TemplateResponse; use OCP\AppFramework\Middleware; use OCP\AppFramework\OCSController; use OCP\IL10N; -use OCP\ILogger; use OCP\INavigationManager; use OCP\IRequest; use OCP\IURLGenerator; use OCP\Util; +use Psr\Log\LoggerInterface; /** * Used to do all the authentication and checking stuff for a controller method @@ -78,7 +78,7 @@ class SecurityMiddleware extends Middleware { private $appName; /** @var IURLGenerator */ private $urlGenerator; - /** @var ILogger */ + /** @var LoggerInterface */ private $logger; /** @var bool */ private $isLoggedIn; @@ -95,7 +95,7 @@ class SecurityMiddleware extends Middleware { ControllerMethodReflector $reflector, INavigationManager $navigationManager, IURLGenerator $urlGenerator, - ILogger $logger, + LoggerInterface $logger, string $appName, bool $isLoggedIn, bool $isAdminUser, @@ -233,9 +233,8 @@ class SecurityMiddleware extends Middleware { } } - $this->logger->logException($exception, [ - 'level' => ILogger::DEBUG, - 'app' => 'core', + $this->logger->debug($exception->getMessage(), [ + 'exception' => $exception, ]); return $response; } diff --git a/lib/private/Avatar/Avatar.php b/lib/private/Avatar/Avatar.php index f716c567c79..bd40766afcb 100644 --- a/lib/private/Avatar/Avatar.php +++ b/lib/private/Avatar/Avatar.php @@ -43,14 +43,14 @@ use OC\Color; use OC_Image; use OCP\Files\NotFoundException; use OCP\IAvatar; -use OCP\ILogger; +use Psr\Log\LoggerInterface; /** * This class gets and sets users avatars. */ abstract class Avatar implements IAvatar { - /** @var ILogger */ + /** @var LoggerInterface */ protected $logger; /** @@ -69,12 +69,7 @@ abstract class Avatar implements IAvatar { <text x="50%" y="350" style="font-weight:normal;font-size:280px;font-family:\'Noto Sans\';text-anchor:middle;fill:#fff">{letter}</text> </svg>'; - /** - * The base avatar constructor. - * - * @param ILogger $logger The logger - */ - public function __construct(ILogger $logger) { + public function __construct(LoggerInterface $logger) { $this->logger = $logger; } diff --git a/lib/private/Avatar/AvatarManager.php b/lib/private/Avatar/AvatarManager.php index 04d3a721022..c54539b2cde 100644 --- a/lib/private/Avatar/AvatarManager.php +++ b/lib/private/Avatar/AvatarManager.php @@ -45,8 +45,8 @@ use OCP\IAvatar; use OCP\IAvatarManager; use OCP\IConfig; use OCP\IL10N; -use OCP\ILogger; use OCP\IUserSession; +use Psr\Log\LoggerInterface; /** * This class implements methods to access Avatar functionality @@ -65,7 +65,7 @@ class AvatarManager implements IAvatarManager { /** @var IL10N */ private $l; - /** @var ILogger */ + /** @var LoggerInterface */ private $logger; /** @var IConfig */ @@ -77,22 +77,12 @@ class AvatarManager implements IAvatarManager { /** @var KnownUserService */ private $knownUserService; - /** - * AvatarManager constructor. - * - * @param Manager $userManager - * @param IAppData $appData - * @param IL10N $l - * @param ILogger $logger - * @param IConfig $config - * @param IUserSession $userSession - */ public function __construct( IUserSession $userSession, Manager $userManager, IAppData $appData, IL10N $l, - ILogger $logger, + LoggerInterface $logger, IConfig $config, IAccountManager $accountManager, KnownUserService $knownUserService diff --git a/lib/private/Avatar/GuestAvatar.php b/lib/private/Avatar/GuestAvatar.php index cc7e21b9fe6..c208353d726 100644 --- a/lib/private/Avatar/GuestAvatar.php +++ b/lib/private/Avatar/GuestAvatar.php @@ -27,7 +27,7 @@ declare(strict_types=1); namespace OC\Avatar; use OCP\Files\SimpleFS\InMemoryFile; -use OCP\ILogger; +use Psr\Log\LoggerInterface; /** * This class represents a guest user's avatar. @@ -44,9 +44,9 @@ class GuestAvatar extends Avatar { * GuestAvatar constructor. * * @param string $userDisplayName The guest user display name - * @param ILogger $logger The logger + * @param LoggerInterface $logger The logger */ - public function __construct(string $userDisplayName, ILogger $logger) { + public function __construct(string $userDisplayName, LoggerInterface $logger) { parent::__construct($logger); $this->userDisplayName = $userDisplayName; } diff --git a/lib/private/Avatar/PlaceholderAvatar.php b/lib/private/Avatar/PlaceholderAvatar.php index 5883fe531a3..377b5e03654 100644 --- a/lib/private/Avatar/PlaceholderAvatar.php +++ b/lib/private/Avatar/PlaceholderAvatar.php @@ -38,7 +38,7 @@ use OCP\Files\SimpleFS\ISimpleFolder; use OCP\IConfig; use OCP\IImage; use OCP\IL10N; -use OCP\ILogger; +use Psr\Log\LoggerInterface; /** * This class represents a registered user's placeholder avatar. @@ -60,12 +60,12 @@ class PlaceholderAvatar extends Avatar { * @param ISimpleFolder $folder The avatar files folder * @param IL10N $l The localization helper * @param User $user The user this class manages the avatar for - * @param ILogger $logger The logger + * @param LoggerInterface $logger The logger */ public function __construct( ISimpleFolder $folder, $user, - ILogger $logger) { + LoggerInterface $logger) { parent::__construct($logger); $this->folder = $folder; diff --git a/lib/private/Avatar/UserAvatar.php b/lib/private/Avatar/UserAvatar.php index f47809425ed..970548f8c8e 100644 --- a/lib/private/Avatar/UserAvatar.php +++ b/lib/private/Avatar/UserAvatar.php @@ -39,7 +39,7 @@ use OCP\Files\SimpleFS\ISimpleFolder; use OCP\IConfig; use OCP\IImage; use OCP\IL10N; -use OCP\ILogger; +use Psr\Log\LoggerInterface; /** * This class represents a registered user's avatar. @@ -64,13 +64,13 @@ class UserAvatar extends Avatar { * @param ISimpleFolder $folder The avatar files folder * @param IL10N $l The localization helper * @param User $user The user this class manages the avatar for - * @param ILogger $logger The logger + * @param LoggerInterface $logger The logger */ public function __construct( ISimpleFolder $folder, IL10N $l, $user, - ILogger $logger, + LoggerInterface $logger, IConfig $config) { parent::__construct($logger); $this->folder = $folder; diff --git a/lib/private/CapabilitiesManager.php b/lib/private/CapabilitiesManager.php index 6a4d97ad159..efa1cff5146 100644 --- a/lib/private/CapabilitiesManager.php +++ b/lib/private/CapabilitiesManager.php @@ -32,17 +32,17 @@ namespace OC; use OCP\AppFramework\QueryException; use OCP\Capabilities\ICapability; use OCP\Capabilities\IPublicCapability; -use OCP\ILogger; +use Psr\Log\LoggerInterface; class CapabilitiesManager { /** @var \Closure[] */ private $capabilities = []; - /** @var ILogger */ + /** @var LoggerInterface */ private $logger; - public function __construct(ILogger $logger) { + public function __construct(LoggerInterface $logger) { $this->logger = $logger; } @@ -59,10 +59,8 @@ class CapabilitiesManager { try { $c = $capability(); } catch (QueryException $e) { - $this->logger->logException($e, [ - 'message' => 'CapabilitiesManager', - 'level' => ILogger::ERROR, - 'app' => 'core', + $this->logger->error('CapabilitiesManager', [ + 'exception' => $e, ]); continue; } diff --git a/lib/private/Collaboration/Collaborators/LookupPlugin.php b/lib/private/Collaboration/Collaborators/LookupPlugin.php index f675cece99e..3d118989cc6 100644 --- a/lib/private/Collaboration/Collaborators/LookupPlugin.php +++ b/lib/private/Collaboration/Collaborators/LookupPlugin.php @@ -33,9 +33,9 @@ use OCP\Collaboration\Collaborators\SearchResultType; use OCP\Federation\ICloudIdManager; use OCP\Http\Client\IClientService; use OCP\IConfig; -use OCP\ILogger; use OCP\IUserSession; use OCP\Share\IShare; +use Psr\Log\LoggerInterface; class LookupPlugin implements ISearchPlugin { @@ -47,14 +47,14 @@ class LookupPlugin implements ISearchPlugin { private $currentUserRemote; /** @var ICloudIdManager */ private $cloudIdManager; - /** @var ILogger */ + /** @var LoggerInterface */ private $logger; public function __construct(IConfig $config, IClientService $clientService, IUserSession $userSession, ICloudIdManager $cloudIdManager, - ILogger $logger) { + LoggerInterface $logger) { $this->config = $config; $this->clientService = $clientService; $this->cloudIdManager = $cloudIdManager; @@ -96,8 +96,9 @@ class LookupPlugin implements ISearchPlugin { try { $remote = $this->cloudIdManager->resolveCloudId($lookup['federationId'])->getRemote(); } catch (\Exception $e) { - $this->logger->error('Can not parse federated cloud ID "' . $lookup['federationId'] . '"'); - $this->logger->error($e->getMessage()); + $this->logger->error('Can not parse federated cloud ID "' . $lookup['federationId'] . '"', [ + 'exception' => $e, + ]); continue; } if ($this->currentUserRemote === $remote) { diff --git a/lib/private/Collaboration/Resources/Manager.php b/lib/private/Collaboration/Resources/Manager.php index 97213c45669..a84ca4da241 100644 --- a/lib/private/Collaboration/Resources/Manager.php +++ b/lib/private/Collaboration/Resources/Manager.php @@ -38,8 +38,8 @@ use OCP\Collaboration\Resources\IResource; use OCP\Collaboration\Resources\ResourceException; use OCP\DB\QueryBuilder\IQueryBuilder; use OCP\IDBConnection; -use OCP\ILogger; use OCP\IUser; +use Psr\Log\LoggerInterface; class Manager implements IManager { public const TABLE_COLLECTIONS = 'collres_collections'; @@ -50,14 +50,14 @@ class Manager implements IManager { protected $connection; /** @var IProviderManager */ protected $providerManager; - /** @var ILogger */ + /** @var LoggerInterface */ protected $logger; /** @var string[] */ protected $providers = []; - public function __construct(IDBConnection $connection, IProviderManager $providerManager, ILogger $logger) { + public function __construct(IDBConnection $connection, IProviderManager $providerManager, LoggerInterface $logger) { $this->connection = $connection; $this->providerManager = $providerManager; $this->logger = $logger; diff --git a/lib/private/Collaboration/Resources/ProviderManager.php b/lib/private/Collaboration/Resources/ProviderManager.php index 095ffdcd8ee..71e7d8b7e2e 100644 --- a/lib/private/Collaboration/Resources/ProviderManager.php +++ b/lib/private/Collaboration/Resources/ProviderManager.php @@ -29,8 +29,8 @@ namespace OC\Collaboration\Resources; use OCP\AppFramework\QueryException; use OCP\Collaboration\Resources\IProvider; use OCP\Collaboration\Resources\IProviderManager; -use OCP\ILogger; use OCP\IServerContainer; +use Psr\Log\LoggerInterface; class ProviderManager implements IProviderManager { @@ -43,10 +43,10 @@ class ProviderManager implements IProviderManager { /** @var IServerContainer */ protected $serverContainer; - /** @var ILogger */ + /** @var LoggerInterface */ protected $logger; - public function __construct(IServerContainer $serverContainer, ILogger $logger) { + public function __construct(IServerContainer $serverContainer, LoggerInterface $logger) { $this->serverContainer = $serverContainer; $this->logger = $logger; } @@ -57,8 +57,8 @@ class ProviderManager implements IProviderManager { try { $this->providerInstances[] = $this->serverContainer->query($provider); } catch (QueryException $e) { - $this->logger->logException($e, [ - 'message' => "Could not query resource provider $provider: " . $e->getMessage() + $this->logger->error("Could not query resource provider $provider: " . $e->getMessage(), [ + 'exception' => $e, ]); } } diff --git a/lib/private/Console/Application.php b/lib/private/Console/Application.php index 9b1cc57aed3..06edf62147e 100644 --- a/lib/private/Console/Application.php +++ b/lib/private/Console/Application.php @@ -37,8 +37,8 @@ use OC_App; use OCP\AppFramework\QueryException; use OCP\Console\ConsoleEvent; use OCP\IConfig; -use OCP\ILogger; use OCP\IRequest; +use Psr\Log\LoggerInterface; use Symfony\Component\Console\Application as SymfonyApplication; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Input\InputOption; @@ -53,22 +53,15 @@ class Application { private $dispatcher; /** @var IRequest */ private $request; - /** @var ILogger */ + /** @var LoggerInterface */ private $logger; /** @var MemoryInfo */ private $memoryInfo; - /** - * @param IConfig $config - * @param EventDispatcherInterface $dispatcher - * @param IRequest $request - * @param ILogger $logger - * @param MemoryInfo $memoryInfo - */ public function __construct(IConfig $config, EventDispatcherInterface $dispatcher, IRequest $request, - ILogger $logger, + LoggerInterface $logger, MemoryInfo $memoryInfo) { $defaults = \OC::$server->getThemingDefaults(); $this->config = $config; @@ -142,7 +135,9 @@ class Application { try { require $file; } catch (\Exception $e) { - $this->logger->logException($e); + $this->logger->error($e->getMessage(), [ + 'exception' => $e, + ]); } } } diff --git a/lib/private/InitialStateService.php b/lib/private/InitialStateService.php index bbc893269f7..38de49b4780 100644 --- a/lib/private/InitialStateService.php +++ b/lib/private/InitialStateService.php @@ -33,12 +33,12 @@ use OC\AppFramework\Bootstrap\Coordinator; use OCP\AppFramework\QueryException; use OCP\AppFramework\Services\InitialStateProvider; use OCP\IInitialStateService; -use OCP\ILogger; use OCP\IServerContainer; +use Psr\Log\LoggerInterface; class InitialStateService implements IInitialStateService { - /** @var ILogger */ + /** @var LoggerInterface */ private $logger; /** @var string[][] */ @@ -53,7 +53,7 @@ class InitialStateService implements IInitialStateService { /** @var IServerContainer */ private $container; - public function __construct(ILogger $logger, Coordinator $bootstrapCoordinator, IServerContainer $container) { + public function __construct(LoggerInterface $logger, Coordinator $bootstrapCoordinator, IServerContainer $container) { $this->logger = $logger; $this->bootstrapCoordinator = $bootstrapCoordinator; $this->container = $container; @@ -118,9 +118,8 @@ class InitialStateService implements IInitialStateService { $provider = $this->container->query($initialState->getService()); } catch (QueryException $e) { // Log an continue. We can be fault tolerant here. - $this->logger->logException($e, [ - 'message' => 'Could not load initial state provider dynamically: ' . $e->getMessage(), - 'level' => ILogger::ERROR, + $this->logger->error('Could not load initial state provider dynamically: ' . $e->getMessage(), [ + 'exception' => $e, 'app' => $initialState->getAppId(), ]); continue; diff --git a/lib/private/Installer.php b/lib/private/Installer.php index da3cef7d1e7..432f5c526ad 100644 --- a/lib/private/Installer.php +++ b/lib/private/Installer.php @@ -54,6 +54,7 @@ use OCP\IConfig; use OCP\ILogger; use OCP\ITempManager; use phpseclib\File\X509; +use Psr\Log\LoggerInterface; /** * This class provides the functionality needed to install, update and remove apps @@ -65,7 +66,7 @@ class Installer { private $clientService; /** @var ITempManager */ private $tempManager; - /** @var ILogger */ + /** @var LoggerInterface */ private $logger; /** @var IConfig */ private $config; @@ -76,18 +77,11 @@ class Installer { /** @var bool */ private $isCLI; - /** - * @param AppFetcher $appFetcher - * @param IClientService $clientService - * @param ITempManager $tempManager - * @param ILogger $logger - * @param IConfig $config - */ public function __construct( AppFetcher $appFetcher, IClientService $clientService, ITempManager $tempManager, - ILogger $logger, + LoggerInterface $logger, IConfig $config, bool $isCLI ) { @@ -201,9 +195,8 @@ class Installer { try { $this->downloadApp($appId, $allowUnstable); } catch (\Exception $e) { - $this->logger->logException($e, [ - 'level' => ILogger::ERROR, - 'app' => 'core', + $this->logger->error($e->getMessage(), [ + 'exception' => $e, ]); return false; } diff --git a/lib/private/Setup.php b/lib/private/Setup.php index 98cf11e3a87..fe658b2eedd 100644 --- a/lib/private/Setup.php +++ b/lib/private/Setup.php @@ -60,8 +60,8 @@ use OCP\AppFramework\Utility\ITimeFactory; use OCP\Defaults; use OCP\IGroup; use OCP\IL10N; -use OCP\ILogger; use OCP\Security\ISecureRandom; +use Psr\Log\LoggerInterface; class Setup { /** @var SystemConfig */ @@ -72,28 +72,19 @@ class Setup { protected $l10n; /** @var Defaults */ protected $defaults; - /** @var ILogger */ + /** @var LoggerInterface */ protected $logger; /** @var ISecureRandom */ protected $random; /** @var Installer */ protected $installer; - /** - * @param SystemConfig $config - * @param IniGetWrapper $iniWrapper - * @param IL10N $l10n - * @param Defaults $defaults - * @param ILogger $logger - * @param ISecureRandom $random - * @param Installer $installer - */ public function __construct( SystemConfig $config, IniGetWrapper $iniWrapper, IL10N $l10n, Defaults $defaults, - ILogger $logger, + LoggerInterface $logger, ISecureRandom $random, Installer $installer ) { @@ -511,7 +502,7 @@ class Setup { \OC::$server->get(IniGetWrapper::class), \OC::$server->getL10N('lib'), \OC::$server->query(Defaults::class), - \OC::$server->getLogger(), + \OC::$server->get(LoggerInterface::class), \OC::$server->getSecureRandom(), \OC::$server->query(Installer::class) ); diff --git a/lib/private/Setup/AbstractDatabase.php b/lib/private/Setup/AbstractDatabase.php index 77f3c02f9f6..5b975bcfcca 100644 --- a/lib/private/Setup/AbstractDatabase.php +++ b/lib/private/Setup/AbstractDatabase.php @@ -34,8 +34,8 @@ use OC\DB\ConnectionFactory; use OC\DB\MigrationService; use OC\SystemConfig; use OCP\IL10N; -use OCP\ILogger; use OCP\Security\ISecureRandom; +use Psr\Log\LoggerInterface; abstract class AbstractDatabase { @@ -55,12 +55,12 @@ abstract class AbstractDatabase { protected $tablePrefix; /** @var SystemConfig */ protected $config; - /** @var ILogger */ + /** @var LoggerInterface */ protected $logger; /** @var ISecureRandom */ protected $random; - public function __construct(IL10N $trans, SystemConfig $config, ILogger $logger, ISecureRandom $random) { + public function __construct(IL10N $trans, SystemConfig $config, LoggerInterface $logger, ISecureRandom $random) { $this->trans = $trans; $this->config = $config; $this->logger = $logger; diff --git a/lib/private/Setup/MySQL.php b/lib/private/Setup/MySQL.php index 229d47160f5..c2b0cd8aaac 100644 --- a/lib/private/Setup/MySQL.php +++ b/lib/private/Setup/MySQL.php @@ -84,9 +84,8 @@ class MySQL extends AbstractDatabase { $query = "CREATE DATABASE IF NOT EXISTS `$name` CHARACTER SET $characterSet COLLATE ${characterSet}_bin;"; $connection->executeUpdate($query); } catch (\Exception $ex) { - $this->logger->logException($ex, [ - 'message' => 'Database creation failed.', - 'level' => ILogger::ERROR, + $this->logger->error('Database creation failed.', [ + 'exception' => $ex, 'app' => 'mysql.setup', ]); return; @@ -97,9 +96,8 @@ class MySQL extends AbstractDatabase { $query = "GRANT SELECT, INSERT, UPDATE, DELETE, CREATE, DROP, REFERENCES, INDEX, ALTER, CREATE TEMPORARY TABLES, LOCK TABLES, EXECUTE, CREATE VIEW, SHOW VIEW, CREATE ROUTINE, ALTER ROUTINE, EVENT, TRIGGER ON `$name` . * TO '$user'"; $connection->executeUpdate($query); } catch (\Exception $ex) { - $this->logger->logException($ex, [ - 'message' => 'Could not automatically grant privileges, this can be ignored if database user already had privileges.', - 'level' => ILogger::DEBUG, + $this->logger->debug('Could not automatically grant privileges, this can be ignored if database user already had privileges.', [ + 'exception' => $ex, 'app' => 'mysql.setup', ]); } @@ -128,9 +126,8 @@ class MySQL extends AbstractDatabase { $connection->executeUpdate($query); } } catch (\Exception $ex) { - $this->logger->logException($ex, [ - 'message' => 'Database user creation failed.', - 'level' => ILogger::ERROR, + $this->logger->error('Database user creation failed.',[ + 'exception' => $ex, 'app' => 'mysql.setup', ]); } diff --git a/lib/private/Updater.php b/lib/private/Updater.php index 78c652b6ee4..964fd2ad102 100644 --- a/lib/private/Updater.php +++ b/lib/private/Updater.php @@ -59,7 +59,7 @@ use Symfony\Component\EventDispatcher\GenericEvent; */ class Updater extends BasicEmitter { - /** @var ILogger $log */ + /** @var LoggerInterface */ private $log; /** @var IConfig */ @@ -79,15 +79,9 @@ class Updater extends BasicEmitter { 4 => 'Fatal', ]; - /** - * @param IConfig $config - * @param Checker $checker - * @param ILogger $log - * @param Installer $installer - */ public function __construct(IConfig $config, Checker $checker, - ILogger $log = null, + ?LoggerInterface $log, Installer $installer) { $this->log = $log; $this->config = $config; @@ -132,11 +126,15 @@ class Updater extends BasicEmitter { try { $this->doUpgrade($currentVersion, $installedVersion); } catch (HintException $exception) { - $this->log->logException($exception, ['app' => 'core']); + $this->log->error($exception->getMessage(), [ + 'exception' => $exception, + ]); $this->emit('\OC\Updater', 'failure', [$exception->getMessage() . ': ' .$exception->getHint()]); $success = false; } catch (\Exception $exception) { - $this->log->logException($exception, ['app' => 'core']); + $this->log->error($exception->getMessage(), [ + 'exception' => $exception, + ]); $this->emit('\OC\Updater', 'failure', [get_class($exception) . ': ' .$exception->getMessage()]); $success = false; } @@ -272,7 +270,10 @@ class Updater extends BasicEmitter { $errors = Installer::installShippedApps(true); foreach ($errors as $appId => $exception) { /** @var \Exception $exception */ - $this->log->logException($exception, ['app' => $appId]); + $this->log->error($exception->getMessage(), [ + 'exception' => $exception, + 'app' => $appId, + ]); $this->emit('\OC\Updater', 'failure', [$appId . ': ' . $exception->getMessage()]); } @@ -424,7 +425,9 @@ class Updater extends BasicEmitter { $ocApp->enable($app); } } catch (\Exception $ex) { - $this->log->logException($ex, ['app' => 'core']); + $this->log->error($ex->getMessage(), [ + 'exception' => $ex, + ]); } } } |