diff --git a/src/Logger.php b/src/Logger.php index db8d582..b9d4a2f 100644 --- a/src/Logger.php +++ b/src/Logger.php @@ -145,6 +145,6 @@ private function prepareValue(mixed $value): string return (string) $value; } - return \json_encode($value, JSON_THROW_ON_ERROR); + return \json_encode($value, \JSON_THROW_ON_ERROR | \JSON_UNESCAPED_SLASHES | \JSON_UNESCAPED_UNICODE); } } diff --git a/tests/LoggerTest.php b/tests/LoggerTest.php index 256524c..b0951fe 100644 --- a/tests/LoggerTest.php +++ b/tests/LoggerTest.php @@ -38,6 +38,7 @@ public function __toString(): string yield 'null' => [null, 'null']; yield 'list' => [[1, 'two'], '[1,"two"]']; yield 'map' => [['a' => ['b' => 1]], '{"a":{"b":1}}']; + yield 'slashes and unicode' => [['path' => '/var/log', 'name' => 'Дорога'], '{"path":"/var/log","name":"Дорога"}']; } public function testErrorCall(): void diff --git a/tests/RpcMock.php b/tests/RpcMock.php index d6c6f01..86fdee1 100644 --- a/tests/RpcMock.php +++ b/tests/RpcMock.php @@ -66,7 +66,13 @@ public function assertCalledWithContext(LogLevel $level, array $message, int $ti ->with( $level->name . 'WithContext', \Mockery::on(function (LogEntry $logEntry) use ($message): bool { - Assert::same($logEntry->serializeToJsonString(), \json_encode($message)); + // Not via serializeToJsonString(): its escaping of `/` differs between protobuf builds + $attributes = []; + foreach ($logEntry->getLogAttrs() as $attr) { + $attributes[] = ['key' => $attr->getKey(), 'value' => $attr->getValue()]; + } + + Assert::same(['message' => $logEntry->getMessage(), 'logAttrs' => $attributes], $message); return true; }), )