Skip to content

feat: support logfmt layout #114

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

Merged
merged 8 commits into from
Apr 1, 2025
Merged

feat: support logfmt layout #114

merged 8 commits into from
Apr 1, 2025

Conversation

kemingy
Copy link
Contributor

@kemingy kemingy commented Mar 24, 2025

This closes #98.

@tisonkun
Copy link
Contributor

Thank you! I'll review this patch by the end of next week. Feel free to ping me if I meet the estimate.

@kemingy
Copy link
Contributor Author

kemingy commented Mar 30, 2025

@kemingy kemingy requested a review from tisonkun March 31, 2025 13:07
@tisonkun
Copy link
Contributor

tisonkun commented Apr 1, 2025

Yeah. I think that if the key/value has \r\n\\\t\b there would be some issue. But let's simply implement what logfmt does so far and update if any user complain.

Signed-off-by: tison <[email protected]>
Comment on lines +76 to +79
if key.contains([' ', '=', '"']) {
// omit keys contain special chars
return;
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe return an error as go logfmt does. But it would require diagnostic visitor's visit failable and I'll leave it for a follow-up.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Will the key contain special chars? AFAIK, it's set from the log with feature kv like:

info!(key = "something else"; "here is the msg");

It's guaranteed by the compiler.

Copy link
Contributor

Choose a reason for hiding this comment

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

This is possible and how go logfmt implements it.

It's guaranteed by the compiler.

The compiler guarantees it's an expr; nothing more. https://github.com/rust-lang/log/blob/71d533f9bb35fcbb75979ad4fe9743b80c6a8ba4/src/macros.rs#L445-L454

Copy link
Contributor Author

Choose a reason for hiding this comment

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

TIL. Thanks for the information.

Copy link
Contributor

@tisonkun tisonkun left a comment

Choose a reason for hiding this comment

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

LGTM. Pending for merging.

@tisonkun tisonkun merged commit ab10f76 into fast:main Apr 1, 2025
9 checks passed
@tisonkun
Copy link
Contributor

tisonkun commented Apr 1, 2025

Thanks for your contribution!

@kemingy kemingy deleted the logfmt branch April 1, 2025 13:29
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.

Implement logfmt layout
2 participants