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

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