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

Fix duplicate fields in logging example #779

Merged
merged 1 commit into from
Jan 9, 2023
Merged

Fix duplicate fields in logging example #779

merged 1 commit into from
Jan 9, 2023

Conversation

nchengyeeshen
Copy link
Contributor

In some cases, logs will contain duplicate fields.

Here's an example.

{
    "level": "INFO",
    "msg": "request started",
    "ts": "Sat, 07 Jan 2023 02:15:16 UTC",  // Duplicate
    "req_id": "hostname/MlcrKoeXEN-000001",  // Duplicate
    "http_scheme": "http",
    "http_proto": "HTTP/1.1",
    "http_method": "GET",
    "remote_addr": "127.0.0.1:52572",
    "user_agent": "curl/7.85.0",
    "uri": "http://localhost:3333/",
    "ts": "Sat, 07 Jan 2023 02:15:16 UTC",  // Duplicate
    "req_id": "hostname/MlcrKoeXEN-000001"  // Duplicate
}

Since entry.Logger already contains all the fields we want to specify, there is no need to pass in logFields... again.

Here's the output after the change.

{
    "level": "INFO",
    "msg": "request started",
    "ts": "Sat, 07 Jan 2023 02:15:37 UTC",
    "req_id": "hostname/Hkbv1XUDxM-000001",
    "http_scheme": "http",
    "http_proto": "HTTP/1.1",
    "http_method": "GET",
    "remote_addr": "127.0.0.1:52581",
    "user_agent": "curl/7.85.0",
    "uri": "http://localhost:3333/"
}

Copy link
Contributor

@VojtechVitek VojtechVitek left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@pkieltyka pkieltyka merged commit df664f1 into go-chi:master Jan 9, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants