-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathContentReleaseLogger.php
More file actions
90 lines (72 loc) · 3.5 KB
/
ContentReleaseLogger.php
File metadata and controls
90 lines (72 loc) · 3.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
<?php
namespace Flowpack\DecoupledContentStore\Core\Infrastructure;
use Flowpack\DecoupledContentStore\Core\Domain\ValueObject\ContentReleaseIdentifier;
use Flowpack\DecoupledContentStore\NodeRendering\Dto\RendererIdentifier;
use Neos\Flow\Cli\ConsoleOutput;
use Symfony\Component\Console\Output\OutputInterface;
class ContentReleaseLogger
{
/**
* @var OutputInterface
*/
protected $output;
/**
* @var StatisticsEventOutputInterface
*/
protected $statisticsEventOutput;
/**
* @var ContentReleaseIdentifier
*/
protected $contentReleaseIdentifier;
/**
* @var string
*/
protected $logPrefix = '';
protected function __construct(OutputInterface $output, ContentReleaseIdentifier $contentReleaseIdentifier, StatisticsEventOutputInterface $statisticsEventOutput, ?RendererIdentifier $rendererIdentifier)
{
$this->output = $output;
$this->contentReleaseIdentifier = $contentReleaseIdentifier;
$this->statisticsEventOutput = $statisticsEventOutput;
$this->rendererIdentifier = $rendererIdentifier;
$this->logPrefix = '';
if ($this->rendererIdentifier !== null) {
$this->logPrefix = '[Renderer ' . $this->rendererIdentifier->string() . '] ';
}
}
public static function fromConsoleOutput(ConsoleOutput $output, ContentReleaseIdentifier $contentReleaseIdentifier, StatisticsEventOutputInterface $statisticsEventOutput = new RedisStatisticsEventOutput()): self
{
return new static($output->getOutput(), $contentReleaseIdentifier, $statisticsEventOutput, null);
}
public static function fromSymfonyOutput(OutputInterface $output, ContentReleaseIdentifier $contentReleaseIdentifier, StatisticsEventOutputInterface $statisticsEventOutput = new RedisStatisticsEventOutput()): self
{
return new static($output, $contentReleaseIdentifier, $statisticsEventOutput, null);
}
public function debug($message, array $additionalPayload = [])
{
$this->output->writeln($this->logPrefix . 'DEBUG ' . $message . ($additionalPayload ? ' ' . json_encode($additionalPayload) : ''));
}
public function info($message, array $additionalPayload = [])
{
$this->output->writeln($this->logPrefix . 'INFO ' . $message . ($additionalPayload ? ' ' . json_encode($additionalPayload) : ''));
}
public function warn($message, array $additionalPayload = [])
{
$this->output->writeln($this->logPrefix . 'WARN ' . $message . ($additionalPayload ? ' ' . json_encode($additionalPayload) : ''));
}
public function error($message, array $additionalPayload = [])
{
$this->output->writeln($this->logPrefix . 'ERROR ' . $message . ($additionalPayload ? ' ' . json_encode($additionalPayload) : ''));
}
public function logException(\Exception $exception, string $message, array $additionalPayload)
{
$this->output->writeln($this->logPrefix . $message . "\n\n" . $exception->getMessage() . "\n\n" . $exception->getTraceAsString() . "\n\n" . json_encode($additionalPayload));
}
public function logStatisticsEvent(string $event, array $additionalPayload = [])
{
$this->statisticsEventOutput->writeEvent($this->contentReleaseIdentifier, $this->logPrefix, $event, $additionalPayload);
}
public function withRenderer(RendererIdentifier $rendererIdentifier): self
{
return new ContentReleaseLogger($this->output, $this->contentReleaseIdentifier, $this->statisticsEventOutput, $rendererIdentifier);
}
}