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

Open in your IDE?
  1. <?php declare(strict_types=1);
  2. namespace Shopware\Core\Framework\Log;
  3. use Monolog\Logger;
  4. use Shopware\Core\Framework\Event\BusinessEvent;
  5. use Shopware\Core\Framework\Event\BusinessEvents;
  6. use Shopware\Core\Framework\Event\FlowLogEvent;
  7. use Shopware\Core\Framework\Feature;
  8. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  9. /**
  10.  * @deprecated tag:v6.5.0 - reason:becomes-internal - EventSubscribers will become internal in v6.5.0
  11.  */
  12. #[Package('core')]
  13. class LoggingService implements EventSubscriberInterface
  14. {
  15.     /**
  16.      * @deprecated tag:v6.5.0 - property will be private
  17.      */
  18.     protected Logger $logger;
  19.     /**
  20.      * @deprecated tag:v6.5.0 - property will be removed
  21.      *
  22.      * @var array<string, string>
  23.      */
  24.     protected array $subscribedEvents;
  25.     /**
  26.      * @deprecated tag:v6.5.0 - property will be private
  27.      */
  28.     protected string $environment;
  29.     /**
  30.      * @internal
  31.      */
  32.     public function __construct(
  33.         string $kernelEnv,
  34.         Logger $logger
  35.     ) {
  36.         $this->logger $logger;
  37.         $this->environment $kernelEnv;
  38.     }
  39.     /**
  40.      * @deprecated tag:v6.5.0 - Function is deprecated and will be removed.
  41.      */
  42.     public function logBusinessEvent(BusinessEvent $event): void
  43.     {
  44.         Feature::triggerDeprecationOrThrow(
  45.             'v6.5.0.0',
  46.             Feature::deprecatedMethodMessage(__CLASS____METHOD__'v6.5.0.0''logFlowEvent()')
  47.         );
  48.         $innerEvent $event->getEvent();
  49.         $additionalData = [];
  50.         $logLevel Logger::DEBUG;
  51.         if ($innerEvent instanceof LogAwareBusinessEventInterface) {
  52.             $logLevel $innerEvent->getLogLevel();
  53.             $additionalData $innerEvent->getLogData();
  54.         }
  55.         $this->logger->addRecord(
  56.             $logLevel,
  57.             $innerEvent->getName(),
  58.             [
  59.                 'source' => 'core',
  60.                 'environment' => $this->environment,
  61.                 'additionalData' => $additionalData,
  62.             ]
  63.         );
  64.     }
  65.     public function logFlowEvent(FlowLogEvent $event): void
  66.     {
  67.         $innerEvent $event->getEvent();
  68.         $additionalData = [];
  69.         $logLevel Logger::DEBUG;
  70.         if ($innerEvent instanceof LogAware) {
  71.             $logLevel $innerEvent->getLogLevel();
  72.             $additionalData $innerEvent->getLogData();
  73.         }
  74.         $this->logger->addRecord(
  75.             $logLevel,
  76.             $innerEvent->getName(),
  77.             [
  78.                 'source' => 'core',
  79.                 'environment' => $this->environment,
  80.                 'additionalData' => $additionalData,
  81.             ]
  82.         );
  83.     }
  84.     public static function getSubscribedEvents(): array
  85.     {
  86.         if (Feature::isActive('v6.5.0.0')) {
  87.             return [FlowLogEvent::NAME => 'logFlowEvent'];
  88.         }
  89.         return [BusinessEvents::GLOBAL_EVENT => 'logBusinessEvent'];
  90.     }
  91. }