vendor/shopware/core/Framework/Log/LoggingService.php line 25

  1. <?php declare(strict_types=1);
  2. namespace Shopware\Core\Framework\Log;
  3. use Monolog\Level;
  4. use Monolog\Logger;
  5. use Shopware\Core\Framework\Event\FlowLogEvent;
  6. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  7. /**
  8.  * @internal
  9.  */
  10. #[Package('core')]
  11. class LoggingService implements EventSubscriberInterface
  12. {
  13.     /**
  14.      * @internal
  15.      */
  16.     public function __construct(
  17.         private readonly string $environment,
  18.         private readonly Logger $logger
  19.     ) {
  20.     }
  21.     public function logFlowEvent(FlowLogEvent $event): void
  22.     {
  23.         $innerEvent $event->getEvent();
  24.         $additionalData = [];
  25.         $logLevel Level::Debug;
  26.         if ($innerEvent instanceof LogAware) {
  27.             $logLevel $innerEvent->getLogLevel();
  28.             $additionalData $innerEvent->getLogData();
  29.         }
  30.         $this->logger->addRecord(
  31.             $logLevel,
  32.             $innerEvent->getName(),
  33.             [
  34.                 'source' => 'core',
  35.                 'environment' => $this->environment,
  36.                 'additionalData' => $additionalData,
  37.             ]
  38.         );
  39.     }
  40.     public static function getSubscribedEvents(): array
  41.     {
  42.         return [FlowLogEvent::NAME => 'logFlowEvent'];
  43.     }
  44. }