refactor: Migrate away from deprecated ILogger interface to PSR-3
Mostly replace `ILogger` with `LoggerInterface` and some minor cleanup (constructor property promotion). Some places used the deprecated `logException` this is easy to migrate by simply use the appropriate loglevel on the logger and place the exception under the `exception` key in the context. Also the manual checking of the configured log level is not needed, as this is already done by the logger. Signed-off-by: Ferdinand Thiessen <opensource@fthiessen.de>
This commit is contained in:
@@ -10,27 +10,17 @@ use OCA\Deck\Service\DefaultBoardService;
|
||||
use OCA\Deck\Service\PermissionService;
|
||||
use OCP\AppFramework\Middleware;
|
||||
use OCP\IL10N;
|
||||
use OCP\ILogger;
|
||||
use Psr\Log\LoggerInterface;
|
||||
|
||||
class DefaultBoardMiddleware extends Middleware {
|
||||
|
||||
/** @var ILogger */
|
||||
private $logger;
|
||||
/** @var IL10N */
|
||||
private $l10n;
|
||||
/** @var DefaultBoardService */
|
||||
private $defaultBoardService;
|
||||
/** @var PermissionService */
|
||||
private $permissionService;
|
||||
/** @var string|null */
|
||||
private $userId;
|
||||
|
||||
public function __construct(ILogger $logger, IL10N $l10n, DefaultBoardService $defaultBoardService, PermissionService $permissionService, $userId) {
|
||||
$this->logger = $logger;
|
||||
$this->l10n = $l10n;
|
||||
$this->defaultBoardService = $defaultBoardService;
|
||||
$this->permissionService = $permissionService;
|
||||
$this->userId = $userId;
|
||||
public function __construct(
|
||||
private LoggerInterface $logger,
|
||||
private IL10N $l10n,
|
||||
private DefaultBoardService $defaultBoardService,
|
||||
private PermissionService $permissionService,
|
||||
private ?string $userId,
|
||||
) {
|
||||
}
|
||||
|
||||
public function beforeController($controller, $methodName) {
|
||||
@@ -39,7 +29,7 @@ class DefaultBoardMiddleware extends Middleware {
|
||||
$this->defaultBoardService->createDefaultBoard($this->l10n->t('Personal'), $this->userId, '0087C5');
|
||||
}
|
||||
} catch (\Throwable $e) {
|
||||
$this->logger->logException($e);
|
||||
$this->logger->error('Could not create default board', ['exception' => $e]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -15,28 +15,19 @@ use OCP\AppFramework\Middleware;
|
||||
use OCP\AppFramework\OCS\OCSException;
|
||||
use OCP\AppFramework\OCSController;
|
||||
use OCP\IConfig;
|
||||
use OCP\ILogger;
|
||||
use OCP\IRequest;
|
||||
use Psr\Log\LoggerInterface;
|
||||
|
||||
class ExceptionMiddleware extends Middleware {
|
||||
|
||||
/** @var ILogger */
|
||||
private $logger;
|
||||
/** @var IConfig */
|
||||
private $config;
|
||||
/** @var IRequest */
|
||||
private $request;
|
||||
|
||||
/**
|
||||
* SharingMiddleware constructor.
|
||||
*
|
||||
* @param ILogger $logger
|
||||
* @param IConfig $config
|
||||
*/
|
||||
public function __construct(ILogger $logger, IConfig $config, IRequest $request) {
|
||||
$this->logger = $logger;
|
||||
$this->config = $config;
|
||||
$this->request = $request;
|
||||
public function __construct(
|
||||
private LoggerInterface $logger,
|
||||
private IConfig $config,
|
||||
private IRequest $request,
|
||||
) {
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -69,9 +60,7 @@ class ExceptionMiddleware extends Middleware {
|
||||
}
|
||||
|
||||
if ($exception instanceof StatusException) {
|
||||
if ($this->config->getSystemValue('loglevel', ILogger::WARN) === ILogger::DEBUG) {
|
||||
$this->logger->logException($exception);
|
||||
}
|
||||
$this->logger->debug($exception->getMessage(), ['exception' => $exception]);
|
||||
|
||||
if ($exception instanceof ConflictException) {
|
||||
return new JSONResponse([
|
||||
@@ -98,7 +87,7 @@ class ExceptionMiddleware extends Middleware {
|
||||
'message' => $exceptionMessage,
|
||||
'requestId' => $this->request->getId(),
|
||||
];
|
||||
$this->logger->logException($exception);
|
||||
$this->logger->error($exception->getMessage(), ['exception' => $exception]);
|
||||
if ($debugMode === true) {
|
||||
$response['exception'] = (array) $exception;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user