Add key-values to the macros #461
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!461
Loading…
Reference in a new issue
No description provided.
Delete branch "key-value-macros"
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?
Attempt number two/three? Too many in any case.
Previously I proposed a design that followed a
structlike syntax:However it turns out that this does not work well with named arguments
as reported in issues #369 and #372. The implementation was eventually
reverted in pr #374.
This new design takes inspiration from the
tracingcrate which alreadysupports key-value pairs in logging events. The basic idea is to put the
key-value pairs before the message and arguments. Applying the same
structure like syntax as above we would get something like the
following.
But personally I'm not a big fan of this formatting, let's try putting
everything on a single line instead.
A little better, but at this point the structure like syntax is really
more annoying then helpful. So, instead I've done away it, opting
instead use the following syntax.
Two major differences:
:) are replaced with equal/assignment signs (=).This gives us syntax similar to variable assignment.
But then we run in some limitations of the macro syntax, specifically
that
exprfragments aren't allowed afterexprfragments. To fix thisI went with the easiest option of changing the last comma (
,) afterthe key-value pairs to a semicolon (
;). Making the final syntax looklike the following.
Which, in my opinion and all things considered, it's too bad looking.
/cc @KodrAus @yoshuawuyts
Ping @KodrAus.
@sfackler you have the time to look at this?
Hey @Thomasdezeeuw! 👋 Sorry I hadn't gotten to this. My GitHub notifications have been a mess lately. I don't currently have commit access to
logbut can still review in the meantime.We are a bit limited in what we can do with
macro_rules, I think the place you're arriving at is not too bad indeed. Thekey = valuesyntax is more in line withformat_args, but a little inconsistent withtarget. If anything though, I'd considertargetthe inconsistent one.This looks good to me 👍