-
Notifications
You must be signed in to change notification settings - Fork 255
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
Allow macros to be more consistent with kvs #476
Conversation
Did
And replace them with the |
It does work, but when I started using it I found the inconsistency with key values and named format args a bit jarring. We’ll probably want some
Those methods and direct downcasting will just go away, unless it’s something you’re currently using? Speaking of, what do you think of those little macros? The alternative is something like |
I'm not sure. One the one hand I can see your argument, on the other target it is different from the key-values as it has its own method to access it (not via
I do use the downcasting but I'll switch to the visitor API introduces in #467, so a nice deprecation period would be appreciated.
I could either way. The way the tracing crate does is a bit unusual on first sight, but I image you get used to it. So it's a question of being more explicit (macros) vs quicker to write (tracing like flags). I'm with either. |
Ah that's right, you've been forced to use a nasty chain of
You can still specify key-value pairs without having to specify a target: info!(cat_1 = "chashu", cat_2 = "nori", cat_count = 2; "hello {world}", world = "world"); ...but that does raise an interesting forwards compatibility hazard. Say you write: info!(target = "kv_target", cat_1 = "chashu", cat_2 = "nori"; "hello {}", "world"); In this scheme, that
Yeh, I think once you learn the scheme it's not too bad. My main reason not for trying to pursue it here is that I think formatting flags are a bit of a dead end. They're crafted for the needs of I don't want to keep you blocked on this for much longer though, so maybe after we're sure we're not painted into any corners (which I don't think we are this time) we can create a bit of a checklist on #343 of incomplete parts in the macros so they don't need to hold up getting something out? |
I meant going from a log with a target to a log with a target and key-values, for example: // Original:
info!(target: "yak_events", "Commencing yak shaving for {:?}", yak);
// New
info!(target: "yak_events", key = value; "Commencing yak shaving for {:?}", yak); // This won't work.
info!(target = "yak_events", key = value; "Commencing yak shaving for {:?}", yak); // This will. Or am I mistaken here?
I was saying it could be confusing. With your example above it's not clear that target is "special" (in the sense it can be retrieved using And it allows people to use
👍
I think the only decision we need to make is for taget ":" vs "=". We can use macros for formatting and add special tracing-like flags later without breaking compatibility right? |
Sounds good 👍 I’m not too strongly tied to my I would be ok with keeping target using |
Sounds good. I think for backwards compatibility we want to keep |
Ok, I've reverted the need to make use the info!(target = "my_target", cat_1 = "chashu", cat_2 = "nori", cat_count = 2; "hello {}", "world"); In this case we'll interpret $lvl:expr, $($key:ident = $value:expr),+; $($arg:tt)+ where we can use a tt-muncher to unpack the key-value pairs and pick off a Once this is green I'll merge it in and give it a smoke test in any candidate libraries to make sure it doesn't regress things and then get it out the door. |
Part of #436
This tweaks the new key-value macro syntax slightly so that it can be more consistent in cases where key-values are supplied and in cases where they're not. All the old syntax is still supported, but we can now write
log!
macros like:which then supports key-value pairs as:
For key-values, the
target = x;
form is required. It splits our macro up into 3 logical parts, separated by;
s:target = "my_target"
: The portion of the log record that's considered by top-level filtering. It's equivalent tolog_enabled!
.key1 = value1, key2 = value2
: The structured data associated with the log record."format {formatted1}", formatted1 = value1
: The unstructured message associated with the log record.I think for
log
here we should also remove thecapture_*
methods onValue
for now, because they lead to unpleasant compilation errors when you don't have a&T: 'static
around. They're only useful if you want to try downcast to a specific type, like aUuid
orTimestamp
.I'll try flesh out our test coverage even more, since there are a lot of possible permutations of the log macros and their interactions with
format_args
to consider.cc @Thomasdezeeuw. What do you think?