diff --git a/src/bundle/Resources/config/services/events.yaml b/src/bundle/Resources/config/services/events.yaml index d100e7738a..3c36d9c7ec 100644 --- a/src/bundle/Resources/config/services/events.yaml +++ b/src/bundle/Resources/config/services/events.yaml @@ -3,6 +3,8 @@ services: autowire: true autoconfigure: true public: false + bind: + string $logLevel: 'error' EzSystems\EzPlatformAdminUi\EventListener\: resource: "../../../lib/EventListener/*" @@ -38,6 +40,7 @@ services: $entrypointLookupCollection: '@webpack_encore.entrypoint_lookup_collection' tags: - { name: kernel.event_listener, event: kernel.exception } + - { name: monolog.logger, channel: ibexa.admin } EzSystems\EzPlatformAdminUi\EventListener\MenuPermissionsListener: tags: diff --git a/src/lib/EventListener/AdminExceptionListener.php b/src/lib/EventListener/AdminExceptionListener.php index 8464731fda..92259fe8b8 100644 --- a/src/lib/EventListener/AdminExceptionListener.php +++ b/src/lib/EventListener/AdminExceptionListener.php @@ -11,6 +11,8 @@ use eZ\Publish\Core\MVC\Symfony\SiteAccess; use EzSystems\EzPlatformAdminUi\Notification\NotificationHandlerInterface; use EzSystems\EzPlatformAdminUiBundle\EzPlatformAdminUiBundle; +use Psr\Log\LoggerAwareInterface; +use Psr\Log\LoggerAwareTrait; use SplFileInfo; use Symfony\Component\Filesystem\Filesystem; use Symfony\Component\HttpFoundation\Response; @@ -22,8 +24,10 @@ use Twig\Environment; use Twig\Error\RuntimeError; -class AdminExceptionListener +class AdminExceptionListener implements LoggerAwareInterface { + use LoggerAwareTrait; + /** @var \EzSystems\EzPlatformAdminUi\Notification\NotificationHandlerInterface */ protected $notificationHandler; @@ -45,6 +49,9 @@ class AdminExceptionListener /** @var string */ protected $kernelEnvironment; + /** @var \Psr\Log\LogLevel::* */ + private $logLevel; + /** * @param \Twig\Environment $twig * @param \EzSystems\EzPlatformAdminUi\Notification\NotificationHandlerInterface $notificationHandler @@ -53,6 +60,7 @@ class AdminExceptionListener * @param array $siteAccessGroups * @param string $kernelRootDir * @param string $kernelEnvironment + * @param \Psr\Log\LogLevel::* $logLevel */ public function __construct( Environment $twig, @@ -61,7 +69,8 @@ public function __construct( EntrypointLookupCollectionInterface $entrypointLookupCollection, array $siteAccessGroups, string $kernelProjectDir, - string $kernelEnvironment + string $kernelEnvironment, + string $logLevel ) { $this->twig = $twig; $this->notificationHandler = $notificationHandler; @@ -70,6 +79,7 @@ public function __construct( $this->siteAccessGroups = $siteAccessGroups; $this->rootDir = $kernelProjectDir; $this->kernelEnvironment = $kernelEnvironment; + $this->logLevel = $logLevel; } /** @@ -99,6 +109,9 @@ public function onKernelException(ExceptionEvent $event) // map exception to UI notification $this->notificationHandler->error(/** @Ignore */ $this->getNotificationMessage($exception)); + $this->logger->log($this->logLevel, $exception->getMessage(), [ + 'exception' => $exception, + ]); if ($exception instanceof RuntimeError) { // If exception is coming from the template where encore already