Skip to content

Commit 5a5b73e

Browse files
author
Christoph Lehmann
committed
Change log format to JSON
1 parent be0e0a8 commit 5a5b73e

1 file changed

Lines changed: 19 additions & 26 deletions

File tree

Classes/Log/Backend/ConsoleBackend.php

Lines changed: 19 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -44,14 +44,14 @@ class ConsoleBackend extends AbstractBackend
4444
public function open(): void
4545
{
4646
$this->severityLabels = [
47-
LOG_EMERG => 'EMERGENCY',
48-
LOG_ALERT => 'ALERT ',
49-
LOG_CRIT => 'CRITICAL ',
50-
LOG_ERR => 'ERROR ',
51-
LOG_WARNING => 'WARNING ',
52-
LOG_NOTICE => 'NOTICE ',
53-
LOG_INFO => 'INFO ',
54-
LOG_DEBUG => 'DEBUG ',
47+
LOG_EMERG => 'emergency',
48+
LOG_ALERT => 'alert',
49+
LOG_CRIT => 'critical',
50+
LOG_ERR => 'error',
51+
LOG_WARNING => 'warning',
52+
LOG_NOTICE => 'notice',
53+
LOG_INFO => 'info',
54+
LOG_DEBUG => 'debug',
5555
];
5656

5757
$this->streamHandle = fopen('php://' . $this->streamName, 'w');
@@ -85,25 +85,18 @@ public function append(
8585
return;
8686
}
8787

88-
$severityLabel = (isset($this->severityLabels[$severity])) ? $this->severityLabels[$severity] : 'UNKNOWN ';
89-
$output = $severityLabel . ' ' . $message;
90-
if (!empty($this->prefix)) {
91-
$output = $this->prefix . ' ' . $output;
92-
}
93-
if (!empty($packageKey)) {
94-
$output .= sprintf(' package=%s', $packageKey);
95-
}
96-
if (!empty($className)) {
97-
$output .= sprintf(' class=%s', $className);
98-
}
99-
if (!empty($methodName)) {
100-
$output .= sprintf(' method=%s', $methodName);
101-
}
102-
if (!empty($additionalData)) {
103-
$output .= PHP_EOL . (new PlainTextFormatter($additionalData))->format();
104-
}
88+
$data = [
89+
'eventTime' => (new \DateTime('now'))->format(DATE_RFC3339),
90+
'severity' => $this->severityLabels[$severity] ?? 'unknown',
91+
'message' => implode(' ', [trim($this->prefix), $message]),
92+
'class' => $className,
93+
'method' => $methodName,
94+
'package' => $packageKey, // Drop since 'class' is FQDN?
95+
'additionalData' => $additionalData,
96+
'source' => 'neos-flow'
97+
];
10598
if (is_resource($this->streamHandle)) {
106-
fputs($this->streamHandle, $output . PHP_EOL);
99+
fputs($this->streamHandle, json_encode($data, JSON_THROW_ON_ERROR) . PHP_EOL);
107100
}
108101
}
109102

0 commit comments

Comments
 (0)