Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/Logger.php
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@
->call(
$level,
new LogEntry([
'message' => (string) $message,

Check warning on line 115 in src/Logger.php

View workflow job for this annotation

GitHub Actions / mutation

Escaped Mutant for Mutator "CastString": @@ @@ ->call( $level, new LogEntry([ - 'message' => (string) $message, + 'message' => $message, 'log_attrs' => $attrs, ]), );
'log_attrs' => $attrs,
]),
);
Expand Down Expand Up @@ -145,6 +145,6 @@
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);
}
}
1 change: 1 addition & 0 deletions tests/LoggerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 7 additions & 1 deletion tests/RpcMock.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}),
)
Expand Down
Loading