Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

IBX-1948: Log exceptions from admin-ui #2028

Merged
merged 1 commit into from
Feb 10, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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