logger()->info([...]) throws a TypeError although the docs show array messages
Mantenedores costumam responder em até 1 dia
Avaliação
- Dificuldade
- 4/5
- Tempo estimado
- 3-5 dias
- Facilidade para iniciantes
- 42/100
Direção de pesquisa
Read Logger::log(), the nine level methods, ReportableInterface::report(), and LoggerTrait::report() to trace where the array is rejected; compare that behavior with packages/logger/usage.md, packages/logger/adapters.md, architecture.md, and packages/logger/helpers.md. The issue leaves two incompatible approaches open, so first clarify which behavior should be supported. Done means the chosen behavior and docs agree, the corresponding file-adapter test passes, and the listed checks pass on PHP 8.1–8.3 with a changelog entry.
Escrita pelo modelo de indexação a partir do texto da issue.
Descrição
Summary
Passing an array to a Logger method throws a TypeError, but the Logger docs describe array messages as a supported way to log structured data.
What happens
logger()->info(['order' => 1042, 'status' => 'paid']);
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 callslogger()->info([...]).packages/logger/adapters.mdandarchitecture.md: "If you pass an array message, the package JSON-encodes it with pretty printing before writing."packages/logger/helpers.md: uselogger()for "structured array messages".
Cause
Logger::log()and the nine level methods takestring|Stringable $message, and so doesReportableInterface::report().LoggerTrait::report()still containsis_array($message) ? json_encode($message, JSON_PRETTY_PRINT) : (string) $message. That branch can never run, because the parameter type rejects an array first.LoggerimplementsPsr\Log\LoggerInterface, where the message isstring|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|arrayonLoggerandReportableInterface::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$contextin 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 phpstanandcomposer rector:checkpass on PHP 8.1 to 8.3- the changelog lists the change
- Linguagem predominante
- PHP
- Estrelas
- 43
- Forks
- 22
- Merge médio
- 54min
- PRs com merge (30d)
- 57
Preparar o ambiente
- Sem Dockerfile nem arquivo Docker Compose
- Sem modelo de pull request
- Ler o guia de contribuição
Primeiros passos
- Leia a issue inteira e depois o guia de contribuição do projeto.
- Comente na issue dizendo que vai assumir — evita que duas pessoas façam o mesmo trabalho.
- Faça um fork do repositório e trabalhe em uma branch.
- Abra um pull request que referencie o número da issue.
Mais de quantum-php/framework
-
bug good first issue
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 78/100
quantum-php/framework#692 ·
Mantenedores costumam responder em até 1 dia
-
routing testing
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 76/100
quantum-php/framework#547 ·
Mantenedores costumam responder em até 1 dia
-
bug
Dificuldade 3/5 1-2 dias Facilidade para iniciantes 72/100
quantum-php/framework#694 ·
Mantenedores costumam responder em até 1 dia
-
Raise PHPStan to level 9Abertarefactoring tech debt
Dificuldade 5/5 Mais de uma semana Facilidade para iniciantes 20/100
quantum-php/framework#693 ·
Mantenedores costumam responder em até 1 dia
-
install:debugbar reads the package folder from the working directory and uses the default storage adapterTalvez já em andamento @armanist assumiu hoje. Abertabug console debugbar good first issue
quantum-php/framework#691 · 1 responsável ·
Mantenedores costumam responder em até 1 dia
Todas as issues de quantum-php/framework
Issues semelhantes
-
Dificuldade 1/5 Menos de uma hora Facilidade para iniciantes 70/100
ajeetraina/awesome-docker-sbx#559 ·
-
dependencies enhancement
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 68/100
novalo-dev/Prestashop-MCP-Server#329 ·
Mantenedores costumam responder em até 1 dia
-
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 80/100
Mantenedores costumam responder em até 1 dia
-
bug origin:interactive status:available
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 62/100
Ultimate-Multisite/ultimate-multisite#2131 ·
Mantenedores costumam responder em até 1 dia
-
sync-en
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 72/100
Mantenedores costumam responder em até 1 dia