-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathContentReleaseLogger.php
More file actions
84 lines (66 loc) · 2.92 KB
/
ContentReleaseLogger.php
File metadata and controls
84 lines (66 loc) · 2.92 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
<?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 ContentReleaseIdentifier
*/
protected $contentReleaseIdentifier;
protected string $logPrefix = '';
protected ?RendererIdentifier $rendererIdentifier;
protected function __construct(OutputInterface $output, ContentReleaseIdentifier $contentReleaseIdentifier, ?RendererIdentifier $rendererIdentifier)
{
$this->output = $output;
$this->contentReleaseIdentifier = $contentReleaseIdentifier;
$this->rendererIdentifier = $rendererIdentifier;
$this->logPrefix = '';
if ($this->rendererIdentifier !== null) {
$this->logPrefix = '[Renderer ' . $this->rendererIdentifier->string() . '] ';
}
}
public static function fromConsoleOutput(ConsoleOutput $output, ContentReleaseIdentifier $contentReleaseIdentifier): self
{
return new static($output->getOutput(), $contentReleaseIdentifier, null);
}
public static function fromSymfonyOutput(OutputInterface $output, ContentReleaseIdentifier $contentReleaseIdentifier): self
{
return new static($output, $contentReleaseIdentifier, null);
}
public function debug(string $message, array $additionalPayload = []): void
{
$this->logToOutput('DEBUG', $message, $additionalPayload);
}
public function info(string $message, array $additionalPayload = []): void
{
$this->logToOutput('INFO', $message, $additionalPayload);
}
public function warn(string $message, array $additionalPayload = []): void
{
$this->logToOutput('WARNING', $message, $additionalPayload);
}
public function error(string $message, array $additionalPayload = []): void
{
$this->logToOutput('ERROR', $message, $additionalPayload);
}
protected function logToOutput(string $level, string $message, array $additionalPayload = []): void
{
$formattedPayload = $additionalPayload ? ' ' . json_encode($additionalPayload) : '';
$this->output->writeln($this->logPrefix . $level . ': ' . $message . $formattedPayload);
}
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 withRenderer(RendererIdentifier $rendererIdentifier): self
{
return new ContentReleaseLogger($this->output, $this->contentReleaseIdentifier, $rendererIdentifier);
}
}