message should be passed as a format-string and fields #3281
blueforesticarus
started this conversation in
Ideas
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Tracing is aimed toward structured logging. However the trace macros support format string syntax, which gets used often when it doesn't need to be. Ex)
info!("server started on port: {}", port);
should beinfo!(port, "server started")
;Support for format syntax encourages people to use it, and is not necessary if you really need a formatted message.
info!(message = format!("server starting on port {}", port))
is cumbersome enough that it won't be used as a default.Meanwhile, the reason for using the format string in the first place is to control how your log looks visually. This is important and could be accomplished via a
format = "server started on port: {port}"
field, assuming your tracing subscriber supported it.A reasonable default console layer would format the format string with the fields it specifies followed by a map of the other fields.
This would require custom formatting code, as std::fmt cannot be instantiated at runtime, and so would be slower than a normal use format!(...). The tracing macros could parse the format string at compile time, alleviating this.
Beta Was this translation helpful? Give feedback.
All reactions