Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[🐛 BUG]: AppLogger. JSON duplicate "logger" key #2135

Open
1 task done
gam6itko opened this issue Feb 22, 2025 · 1 comment
Open
1 task done

[🐛 BUG]: AppLogger. JSON duplicate "logger" key #2135

gam6itko opened this issue Feb 22, 2025 · 1 comment
Assignees
Labels
B-bug Bug: bug, exception F-need-verification

Comments

@gam6itko
Copy link
Contributor

gam6itko commented Feb 22, 2025

No duplicates 🥲.

  • I have searched for a similar issue in our bug tracker and didn't find any solutions.

What happened?

If we pass key "logger" in context then RR display invalid JSON log with two "logger" keys.

# .rr.yaml
logs:
  mode: production
  level: debug
  encoding: json

https://github.com/roadrunner-php/app-logger/blob/6be59995a76f03b791702ddbe2b47df48bb16e51/src/Logger.php#L99

Image

We have 4 reserved keys

  • level
  • ts
  • logger
  • msg

In this case we have 2 solution:

  1. If reserved keys present in context then they will be prefixed with __.
\RoadRunner\Logger\Logger::log("Hello!", [
    'logger'=> 'foo', 
    'ts' => 'foo', 
    'msg' =>'foo',
    'level' => 'foo'
])

Output

{
  "level": "info",
  "ts": 1740209343338036353,
  "logger": "app",
  "msg": "Hello!",
  "__level": "foo",
  "__ts": "foo",
  "__logger": "foo",
  "__msg": "foo"
}
  1. Replace original keys.
    I think it is very dangerous because user can pass key "logger" with values ["server", "jobs", "http"].

But it's will be good feature. Because we can pass to logger out php monolog logger channel name for further usage in tools like grafana/loki.

https://spiral.dev/docs/basics-logging/current#send-logs-to-a-specific-channel

Version (rr --version)

2025.3.2

How to reproduce the issue?

\RoadRunner\Logger\Logger::log("Hello!", [
    'logger'=> 'foo', 
    'ts' => 'foo', 
    'msg' =>'foo',
    'level' => 'foo'
])
@gam6itko gam6itko added B-bug Bug: bug, exception F-need-verification labels Feb 22, 2025
@gam6itko gam6itko changed the title [🐛 BUG]: JSON duplicate "logger" key [🐛 BUG]: AppLogger. JSON duplicate "logger" key Feb 22, 2025
@rustatian
Copy link
Member

Hey @gam6itko 👋🏻
Why not vise-versa? Why not use __logger for your custom output like this:

\RoadRunner\Logger\Logger::log("Hello!", [
    '__logger'=> 'foo', 
    '__ts' => 'foo', 
    '__msg' =>'foo',
    '__level' => 'foo'
])

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
B-bug Bug: bug, exception F-need-verification
Projects
None yet
Development

No branches or pull requests

2 participants