kv macro support #353
No reviewers
Labels
No labels
bug
duplicate
easy
enhancement
help wanted
invalid
question
rfc
structured-logging
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
gh-rust-lang/log!353
Loading…
Reference in a new issue
No description provided.
Delete branch "kv-support"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Adds key-value support to the log macros. Supersedes #346. Refs #343 #328. Thanks!
Syntax
Tasks
Thanks so much for working on this @yoshuawuyts!
I've just left a comment about how we're capturing values as strings.
@ -1388,3 +1389,4 @@args: fmt::Arguments,level: Level,&(target, module_path, file, line): &(&str, &'static str, &'static str, u32),kvs: Option<&[(&str, &str)]>,We should use
&ToValuehere so that the structure of captured values can be retained. I sketched out the change in https://github.com/yoshuawuyts/kv-log-macro/pull/1Ah, we should also be careful not to regress the
info!("Hello, {value}", value = 42);case, just based onkv-log-macroit looks like our changes to the macro syntax may not support theident = exprsyntax?It does also present a bit of a syntactic oddity, where values interpolated into the message would use the
ident = exprsyntax fromformat_args, but the captured key-value pairs use theident: exprsyntax like structs:I don't think this is necessarily a problem though, but thought it was worth pointing out.
@ -1388,3 +1389,4 @@args: fmt::Arguments,level: Level,&(target, module_path, file, line): &(&str, &'static str, &'static str, u32),kvs: Option<&[(&str, &str)]>,Ohhhh, yesss! -- I wish I'd known about this sooner, haha.
@KodrAus in general it seems we don't have a lot of tests right now -- I was wondering how we might want to go about it?
Yeh, we don't really for the macro syntax, do we. Maybe we could add an integration test file that can do something like this:
So that we can build up a suite for the current syntax.
But I'm happy to sketch that out independently if you like? For now I think if we can try find a way to keep
ident = exprinterpolated values working then we should be good!@KodrAus ohhh, yeah looks like you were onto something there -- I found a bug in my impl which I've fixed, but more importantly the
name = valinterpolated args aren't indeed no longer working. I've added some basic tests for the macros to prevent this from regressing.Though I'm not entirely sure how to fix it, so I'm all ears if you have suggestions!
Hi @yoshuawuyts!
I'm just circling back to this, I'll spend some time playing with the macros too and see where I end up. We might end up having to tweak the syntax a little (which we could do to consider working more nicely with other extensions like #357).
@KodrAus Hi! -- I've been meaning to post an update, but kept putting it off because of reasons, but yea I've spent some time working on this though haven't been able to solve it.
So what seems to be happening is that the macro currently correctly desugars into:
But the output isn't working. Why? Well, it turns out that
format_argsdoesn't know what to do with the types, and doesn't further process them but expands them to literally stay ascat="nori", and then tries to match on them:Now what I suspect is happening here is that
cat="nori"is not the right token type, andformat_argsdoesn't know how to process it. This is where I got stuck, because I don't know how to cast the types inmacro_rulesmacros.I've tried processing it as a
ttstream. And also asserted it's indeed anident(which according to astexplorer.net is the expected type. So well, yeah, that's as far as I got.Hope this was helpful!
@KodrAus did you have any luck getting this to work? If not, perhaps we could ask @dtolnay for help?
Hi @yoshuawuyts! 👋
Sorry I’ve been really scattered over the last few months so haven’t been able to make a lot of progress here. However I’m feeling less concerned about regressing this specific edge-case, and I also think implicit inline format args makes the difference between our binding syntax for format args vs kv pairs much less significant.
So all that’s to say I’d be on board with pushing forward with this!
@KodrAus yay, that's excellent news! I'm very excited for this!
I just pushed a patch to remove the failing tests, meaning this patch should now be ready to be merged! It seems CI is currently not setup, so it can't verify this patch. But hopefully this is good!
Oh dear... Lemme just fix that real quick.
@yoshuawuyts would you like to squash and rebase your commits on the current
master? I'm thinking the reason actions aren't running here is because we're missing the.github/workflowsdirectory on your branch.@KodrAus rebased and force-pushed. Hoping this works! 🤞
Heh, for odd reasons CI is no longer reporting on this branch. My guess is because the repo was migrated it caused some bug in GitHub's UI.
CI link is here: https://github.com/yoshuawuyts/log/runs/295531981 -- it seems
cfg_ifis failing to build?Ah it looks like
cfg-ifhas removed their explicit MSRV, so I'm trying to get everything back into a good state in #362.Not behind a computer right now but we should try running CI again. Looks like #362 got merged two weeks ago.
Yes! Let's merge this in. CI should be good now but if there's any issues I'll get them sorted.
Thanks so much for your patience and effort on this one @yoshuawuyts!
@kodraus Wooot! So happy this got merged! Thank you!
Do you have any idea when this could make it to a release on crates.io? I'm super stoked to start trying it out! ✨
@yoshuawuyts Yeh this is an exciting step forward! I'll put together a release PR today and cc you on it. I might get a few other peeps from Libs to take a look at the diff too just to make sure we haven't missed anything.