@@ -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 */
@@ -24,10 +29,11 @@ class ContentReleaseLogger
2429 */
2530 protected $ logPrefix = '' ;
2631
27- protected function __construct (OutputInterface $ output , ContentReleaseIdentifier $ contentReleaseIdentifier , ?RendererIdentifier $ rendererIdentifier )
32+ protected function __construct (OutputInterface $ output , ContentReleaseIdentifier $ contentReleaseIdentifier , StatisticsEventOutputInterface $ statisticsEventOutput , ?RendererIdentifier $ rendererIdentifier )
2833 {
2934 $ this ->output = $ output ;
3035 $ this ->contentReleaseIdentifier = $ contentReleaseIdentifier ;
36+ $ this ->statisticsEventOutput = $ statisticsEventOutput ;
3137 $ this ->rendererIdentifier = $ rendererIdentifier ;
3238 $ this ->logPrefix = '' ;
3339
@@ -37,14 +43,14 @@ protected function __construct(OutputInterface $output, ContentReleaseIdentifier
3743 }
3844
3945
40- public static function fromConsoleOutput (ConsoleOutput $ output , ContentReleaseIdentifier $ contentReleaseIdentifier ): self
46+ public static function fromConsoleOutput (ConsoleOutput $ output , ContentReleaseIdentifier $ contentReleaseIdentifier, StatisticsEventOutputInterface $ statisticsEventOutput = new RedisStatisticsEventOutput () ): self
4147 {
42- return new static ($ output ->getOutput (), $ contentReleaseIdentifier , null );
48+ return new static ($ output ->getOutput (), $ contentReleaseIdentifier , $ statisticsEventOutput , null );
4349 }
4450
45- public static function fromSymfonyOutput (OutputInterface $ output , ContentReleaseIdentifier $ contentReleaseIdentifier ): self
51+ public static function fromSymfonyOutput (OutputInterface $ output , ContentReleaseIdentifier $ contentReleaseIdentifier, StatisticsEventOutputInterface $ statisticsEventOutput = new RedisStatisticsEventOutput () ): self
4652 {
47- return new static ($ output , $ contentReleaseIdentifier , null );
53+ return new static ($ output , $ contentReleaseIdentifier , $ statisticsEventOutput , null );
4854 }
4955
5056 public function debug ($ message , array $ additionalPayload = [])
@@ -72,8 +78,13 @@ public function logException(\Exception $exception, string $message, array $addi
7278 $ this ->output ->writeln ($ this ->logPrefix . $ message . "\n\n" . $ exception ->getMessage () . "\n\n" . $ exception ->getTraceAsString () . "\n\n" . json_encode ($ additionalPayload ));
7379 }
7480
81+ public function logStatisticsEvent (string $ event , array $ additionalPayload = [])
82+ {
83+ $ this ->statisticsEventOutput ->writeEvent ($ this ->contentReleaseIdentifier , $ this ->logPrefix , $ event , $ additionalPayload );
84+ }
85+
7586 public function withRenderer (RendererIdentifier $ rendererIdentifier ): self
7687 {
77- return new ContentReleaseLogger ($ this ->output , $ this ->contentReleaseIdentifier , $ rendererIdentifier );
88+ return new ContentReleaseLogger ($ this ->output , $ this ->contentReleaseIdentifier , $ this -> statisticsEventOutput , $ rendererIdentifier );
7889 }
7990}
0 commit comments