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

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