You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
logger()->info([...]) throws a TypeError although the docs show array messages #613
TypeError: Quantum\Logger\Logger::info(): Argument #1 ($message) must be of type Stringable|string, array given
I reproduced it on 3.1.0 with a stub adapter. Before 3.1 the Logger methods had no parameter type, but ReportableInterface::report() already required string|Stringable, so the same call could not have worked there either.
What the docs say
packages/logger/usage.md, "Log a structured payload": the example calls logger()->info([...]).
packages/logger/adapters.md and architecture.md: "If you pass an array message, the package JSON-encodes it with pretty printing before writing."
packages/logger/helpers.md: use logger() for "structured array messages".
Cause
Logger::log() and the nine level methods take string|Stringable $message, and so does ReportableInterface::report().
LoggerTrait::report() still contains is_array($message) ? json_encode($message, JSON_PRETTY_PRINT) : (string) $message. That branch can never run, because the parameter type rejects an array first.
Logger implements Psr\Log\LoggerInterface, where the message is string|Stringable. PSR-3 puts structured data in $context, but the docs state that no context rendering happens ("No placeholder interpolation or structured context rendering happens").
Options
Accept arrays. Widen the message type to string|Stringable|array on Logger and ReportableInterface::report(), so the existing JSON branch works. PHP allows widening a parameter type in an override, so the PSR-3 interface still holds. This keeps the docs as they are.
Keep the PSR-3 shape. Remove the array promises from the docs and the dead branch from LoggerTrait, and decide how structured data should be written, for example by rendering $context in the file adapters.
Acceptance criteria
the behavior and the docs agree, whichever option is chosen
a test logs an array through logger() with a file adapter and checks what is written (option 1), or a test checks that the chosen alternative works (option 2)
composer test, composer cs:check, composer phpstan and composer rector:check pass on PHP 8.1 to 8.3
Activity