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

trace: support string interpolation #83

Open
Ralith opened this issue Mar 29, 2019 · 5 comments
Open

trace: support string interpolation #83

Ralith opened this issue Mar 29, 2019 · 5 comments
Labels
crate/tracing Related to the `tracing` crate help wanted Extra attention is needed kind/feature New feature or request

Comments

@Ralith
Copy link
Collaborator

Ralith commented Mar 29, 2019

Log readability is significantly improved by interleaving information with text, rather than supplying a static string followed by a set of key-value pairs. tokio-trace's macros should support constructing such interpolated strings while preserving the interpolated data as structured fields.

Additionally, any out-of-the-box subscribers targeting direct human consumption (such as by printing to stdout) should not duplicate interpolated values in its output. This could be accomplished without compromising support for users that prefer not to use interpolation by using a distinct field name for message strings that include interpolated data, and establishing that human-oriented subscribers should only display unrecognized key-value pairs if an interpolated message field is not present.

@hawkw
Copy link
Member

hawkw commented Mar 29, 2019

I suspect it should be possible to add syntax for interpolating fields into a textual message in tokio-trace's current macros. May just require some thought to make work.

@carllerche carllerche transferred this issue from tokio-rs/tokio Jun 24, 2019
@hawkw hawkw added crate/tracing Related to the `tracing` crate kind/feature New feature or request labels Jun 24, 2019
@hawkw hawkw added the help wanted Extra attention is needed label Jul 3, 2019
@samschlegel
Copy link
Contributor

samschlegel commented Apr 1, 2020

👋 Dropping a line here in reference to a convo in the #tracing channel in Discord.

Currently we use slog in a bunch of our libs/services which has a syntax like

info!(logger, "msg: {}", 1, formatted_field="a"; "additional_field" => 4)

The fields before the ; are used for the format string, and the result of that is used as msg in the json output. The fields after are just added to the json directly.

I'm not actually a huge fan of this, mostly cause it leads to duplication of fields, and the syntax differs between then in a weird wait. Something that might be nice could be if the syntax was basically just like format!/println! but it didn't error when named arguments weren't used, and all named arguments were added as fields, but I haven't totally thought through the implications of that. Like I'm not sure how field = ?value would work if the field was used multiple times, and say we wanted it to be Display in the span/event fields, but Debug in the message

@Ralith
Copy link
Collaborator Author

Ralith commented Jan 3, 2022

Since Rust RFC 2795 will be stabilized in 1.58, the ergonomic semantics outlined by @samschlegel above should soon be achievable. All we'll need to do is modify event! and span! to interpret format arguments as fields, and use implicit format argument captures for them so that unused fields do not become an error.

@CryoMyst
Copy link

CryoMyst commented Apr 6, 2023

Is there anything currently blocking this feature from happening?

@Ralith
Copy link
Collaborator Author

Ralith commented Apr 6, 2023

No, it's fairly straightforwardly doable now, just nobody's had time to get to it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
crate/tracing Related to the `tracing` crate help wanted Extra attention is needed kind/feature New feature or request
Projects
None yet
Development

No branches or pull requests

4 participants