Skip to content
This repository was archived by the owner on Sep 26, 2025. It is now read-only.

Commit 5fb2e35

Browse files
committed
fix(logging): fix linting and potential double json encoding
1 parent 90c336a commit 5fb2e35

File tree

2 files changed

+14
-2
lines changed

2 files changed

+14
-2
lines changed

Classes/Backend/JSONConsoleLogger.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ public function append(string $message, int $severity = LOG_INFO, $additionalDat
6666
'datetime' => new \DateTime('now')
6767
];
6868
$output = json_encode($data);
69-
} catch (\Exception $e) {
69+
} catch (\Throwable $e) {
7070
$data = [
7171
'severity' => $this->severityLabels[LOG_WARNING],
7272
'service' => $this->serviceContext['service'] ?? '',

Classes/ThrowableStorage/ConsoleStorage.php

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,10 +55,22 @@ public function logThrowable(\Throwable $throwable, array $additionalData = []):
5555

5656
$serviceContext = $configurationManager->getConfiguration(ConfigurationManager::CONFIGURATION_TYPE_SETTINGS, 't3n.FlowLog.serviceContext');
5757

58+
/**
59+
* If the message is already json encoded, decode it, else use plain message
60+
* since we want to ensure that the message is not json encoded twice
61+
*/
62+
json_decode($throwable->getMessage());
63+
if (json_last_error() === JSON_ERROR_NONE) {
64+
$message = json_decode($throwable->getMessage(), true);
65+
} else {
66+
$message = $throwable->getMessage();
67+
}
68+
5869
$data = [
5970
'eventTime' => (new \DateTime('now'))->format(DATE_RFC3339),
6071
'serviceContext' => $serviceContext,
61-
'message' => sprintf('PHP Warning: %s' . PHP_EOL . 'Stack trace:' . PHP_EOL . '%s', $throwable->getMessage(), $throwable->getTraceAsString()),
72+
'message' => $message,
73+
'stackTrace' => $throwable->getTrace(),
6274
'context' => [
6375
'httpRequest' => $this->getHttpRequestContext(),
6476
'reportLocation' => [

0 commit comments

Comments
 (0)