Skip to content

Commit

Permalink
IBX-1948 : Log exceptions from admin-ui (#2028)
Browse files Browse the repository at this point in the history
Co-authored-by: Vidar Langseid <vl@ibexa.co>
  • Loading branch information
vidarl and vidarl authored Feb 10, 2023
1 parent 635e494 commit aa7aa34
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
3 changes: 3 additions & 0 deletions src/bundle/Resources/config/services/events.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ services:
autowire: true
autoconfigure: true
public: false
bind:
string $logLevel: 'error'

EzSystems\EzPlatformAdminUi\EventListener\:
resource: "../../../lib/EventListener/*"
Expand Down Expand Up @@ -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:
Expand Down
17 changes: 15 additions & 2 deletions src/lib/EventListener/AdminExceptionListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;

Expand All @@ -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
Expand All @@ -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,
Expand All @@ -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;
Expand All @@ -70,6 +79,7 @@ public function __construct(
$this->siteAccessGroups = $siteAccessGroups;
$this->rootDir = $kernelProjectDir;
$this->kernelEnvironment = $kernelEnvironment;
$this->logLevel = $logLevel;
}

/**
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit aa7aa34

Please # to comment.