@@ -14,6 +14,11 @@ class ContentReleaseLogger
1414 */
1515 protected $ output ;
1616
17+ /**
18+ * @var StatisticsEventOutputInterface
19+ */
20+ protected $ statisticsEventOutput ;
21+
1722 /**
1823 * @var ContentReleaseIdentifier
1924 */
@@ -23,10 +28,11 @@ class ContentReleaseLogger
2328
2429 protected ?RendererIdentifier $ rendererIdentifier ;
2530
26- protected function __construct (OutputInterface $ output , ContentReleaseIdentifier $ contentReleaseIdentifier , ?RendererIdentifier $ rendererIdentifier )
31+ protected function __construct (OutputInterface $ output , ContentReleaseIdentifier $ contentReleaseIdentifier , StatisticsEventOutputInterface $ statisticsEventOutput , ?RendererIdentifier $ rendererIdentifier )
2732 {
2833 $ this ->output = $ output ;
2934 $ this ->contentReleaseIdentifier = $ contentReleaseIdentifier ;
35+ $ this ->statisticsEventOutput = $ statisticsEventOutput ;
3036 $ this ->rendererIdentifier = $ rendererIdentifier ;
3137 $ this ->logPrefix = '' ;
3238
@@ -36,14 +42,14 @@ protected function __construct(OutputInterface $output, ContentReleaseIdentifier
3642 }
3743
3844
39- public static function fromConsoleOutput (ConsoleOutput $ output , ContentReleaseIdentifier $ contentReleaseIdentifier ): self
45+ public static function fromConsoleOutput (ConsoleOutput $ output , ContentReleaseIdentifier $ contentReleaseIdentifier, StatisticsEventOutputInterface $ statisticsEventOutput = new RedisStatisticsEventOutput () ): self
4046 {
41- return new static ($ output ->getOutput (), $ contentReleaseIdentifier , null );
47+ return new static ($ output ->getOutput (), $ contentReleaseIdentifier , $ statisticsEventOutput , null );
4248 }
4349
44- public static function fromSymfonyOutput (OutputInterface $ output , ContentReleaseIdentifier $ contentReleaseIdentifier ): self
50+ public static function fromSymfonyOutput (OutputInterface $ output , ContentReleaseIdentifier $ contentReleaseIdentifier, StatisticsEventOutputInterface $ statisticsEventOutput = new RedisStatisticsEventOutput () ): self
4551 {
46- return new static ($ output , $ contentReleaseIdentifier , null );
52+ return new static ($ output , $ contentReleaseIdentifier , $ statisticsEventOutput , null );
4753 }
4854
4955 public function debug (string $ message , array $ additionalPayload = []): void
@@ -77,8 +83,13 @@ public function logException(\Exception $exception, string $message, array $addi
7783 $ this ->output ->writeln ($ this ->logPrefix . $ message . "\n\n" . $ exception ->getMessage () . "\n\n" . $ exception ->getTraceAsString () . "\n\n" . json_encode ($ additionalPayload ));
7884 }
7985
86+ public function logStatisticsEvent (string $ event , array $ additionalPayload = [])
87+ {
88+ $ this ->statisticsEventOutput ->writeEvent ($ this ->contentReleaseIdentifier , $ this ->logPrefix , $ event , $ additionalPayload );
89+ }
90+
8091 public function withRenderer (RendererIdentifier $ rendererIdentifier ): self
8192 {
82- return new ContentReleaseLogger ($ this ->output , $ this ->contentReleaseIdentifier , $ rendererIdentifier );
93+ return new ContentReleaseLogger ($ this ->output , $ this ->contentReleaseIdentifier , $ this -> statisticsEventOutput , $ rendererIdentifier );
8394 }
8495}
0 commit comments