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

Add support for Key-Value pairs #362

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

ellttBen
Copy link

Hi there,
As discussed in #329, this PR implements support for the log::kv structured logging API.
These are some user-facing choices I have made:

  • Everything is implemented behind a log_kv feature
  • Support is added in the two encoders json and pattern:
    • The json message has an attributes field which is a serialized map of the record's structured logs
    • The pattern encoder has a new K or key_value formatter which functions exactly like the mdc formatter.

If this sounds okay, I can also edit the documentation.

Cargo.toml Show resolved Hide resolved
Copy link
Collaborator

@bconn98 bconn98 left a comment

Choose a reason for hiding this comment

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

Looks great! Lets try and get some more tests in there and the documentation

src/encode/json.rs Outdated Show resolved Hide resolved
src/encode/json.rs Outdated Show resolved Hide resolved
src/encode/json.rs Outdated Show resolved Hide resolved
src/encode/pattern/mod.rs Outdated Show resolved Hide resolved
src/encode/pattern/mod.rs Outdated Show resolved Hide resolved
@ellttBen ellttBen requested a review from bconn98 March 21, 2024 09:07
@codecov-commenter
Copy link

Codecov Report

Attention: Patch coverage is 91.17647% with 3 lines in your changes are missing coverage. Please review.

Project coverage is 64.09%. Comparing base (8ab1b34) to head (24257cf).

Files Patch % Lines
src/encode/pattern/mod.rs 88.46% 3 Missing ⚠️

❗ Your organization needs to install the Codecov GitHub app to enable full functionality.

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #362      +/-   ##
==========================================
+ Coverage   63.39%   64.09%   +0.70%     
==========================================
  Files          24       24              
  Lines        1557     1593      +36     
==========================================
+ Hits          987     1021      +34     
- Misses        570      572       +2     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

src/encode/json.rs Outdated Show resolved Hide resolved
src/encode/pattern/mod.rs Outdated Show resolved Hide resolved
@bconn98 bconn98 linked an issue Apr 4, 2024 that may be closed by this pull request
@ellttBen ellttBen force-pushed the add-kv-support branch 2 times, most recently from 207d3be to 230f2ea Compare May 7, 2024 15:18
@ellttBen
Copy link
Author

ellttBen commented May 7, 2024

Hi, sorry for the delay, I'm still keen to get this merged. I have rebased this PR and squashed the commits. If more documentation is needed I can get that in ASAP as well.

@bconn98
Copy link
Collaborator

bconn98 commented May 12, 2024

I'll take a look at this soon. I'll do my best to get a hold of the project owner and work through our recent batches of PRs

Cargo.toml Show resolved Hide resolved
@ellttBen ellttBen requested a review from bconn98 May 24, 2024 15:12
bconn98
bconn98 previously approved these changes May 30, 2024
@sdroege
Copy link

sdroege commented Jul 3, 2024

What's the status of this PR?

@bconn98
Copy link
Collaborator

bconn98 commented Jul 3, 2024

@sdroege I am targeting next week to start working with the owner of the repo. Appreciate everyone's hard work on the recent batch of MRs and can't wait to get things moving again!

@sdroege
Copy link

sdroege commented Jul 3, 2024

That sounds great, thanks!

Copy link
Owner

@estk estk left a comment

Choose a reason for hiding this comment

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

I left a couple of comments, but looking really good.

One more general question, did you attempt to wrap log::kv::Source in a newtype and impl serde::Serialize on it?

Just wondering because I was thinking about the tradeoffs of allocating a whole BTree vs the annoyance of adding lifetimes to Message.

src/encode/json.rs Outdated Show resolved Hide resolved
src/encode/json.rs Show resolved Hide resolved
src/encode/pattern/mod.rs Show resolved Hide resolved
src/encode/pattern/mod.rs Outdated Show resolved Hide resolved
src/encode/pattern/mod.rs Outdated Show resolved Hide resolved
src/encode/pattern/mod.rs Outdated Show resolved Hide resolved
…encoding. Factor pattern parsing code between MDC and key_value targets
@ellttBen
Copy link
Author

ellttBen commented Jul 9, 2024

Thanks for the review @estk, I have followed your suggestion and investigated directly playing around with Serde traits.
I implemented the suggested review changes, and also changed the approach for json encoding to directly (via a new wrapper type) serializing from the &log::kv::Source dynamic reference. The error handling is a bit finicky with transformations between log::kv::Error and the serializer errors (log::kv::Error::boxed requires Send+Sync, and the serde traits make no such guarantees about allowable errors), but I think overall it makes more sense.

@ellttBen ellttBen requested a review from estk July 9, 2024 16:49
Copy link
Owner

@estk estk left a comment

Choose a reason for hiding this comment

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

nailed it

@estk
Copy link
Owner

estk commented Jul 9, 2024

blocked on #367

@SL-RU
Copy link

SL-RU commented Aug 10, 2024

Hi! What is the current status of the MR?

@bconn98
Copy link
Collaborator

bconn98 commented Aug 10, 2024

Hi! What is the current status of the MR?

@SL-RU we're still waiting on the blocked PR

@@ -1,7 +1,10 @@
[package]
name = "log4rs"
version = "1.3.0"
authors = ["Steven Fackler <sfackler@gmail.com>", "Evan Simmons <esims89@gmail.com>"]
authors = [
Copy link

Choose a reason for hiding this comment

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

I think you need to revert changes in the formatting

Copy link
Author

Choose a reason for hiding this comment

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

Changes have been approved by the maintainers, I'm reluctant to push to the PR at this stage for that reason

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.

Support for Key-Value Pairs
6 participants