custom/plugins/TigerBase/src/Subscriber/LogKernelExceptions.php line 29

Open in your IDE?
  1. <?php declare(strict_types=1);
  2. namespace TigerMedia\Base\Subscriber;
  3. use Psr\Log\LoggerInterface;
  4. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  5. use Symfony\Component\HttpKernel\Event\ExceptionEvent;
  6. use Symfony\Component\HttpKernel\KernelEvents;
  7. use TigerMedia\Base\Service\ConfigurationService;
  8. class LogKernelExceptions implements EventSubscriberInterface
  9. {
  10.     private LoggerInterface $logger;
  11.     private ConfigurationService $configurationService;
  12.     public function __construct(ConfigurationService $configurationServiceLoggerInterface $logger)
  13.     {
  14.         $this->logger $logger;
  15.         $this->configurationService $configurationService;
  16.     }
  17.     public static function getSubscribedEvents(): array
  18.     {
  19.         return [
  20.             KernelEvents::EXCEPTION => 'onKernelException'
  21.         ];
  22.     }
  23.     public function onKernelException(ExceptionEvent $event): void
  24.     {
  25.         if (!$this->configurationService->isErrorLogEnabled()) {
  26.             return;
  27.         }
  28.         $this->logger->error($event->getThrowable()->getMessage(), [
  29.             'exception' => $event->getThrowable(),
  30.         ]);
  31.     }
  32. }