-
Notifications
You must be signed in to change notification settings - Fork 734
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
Introduce a formatter sigil for "alternate" Display
#1311
Comments
I'm open to adding an alt-mode sigil to format specifiers. I imagine what we would want to do is add it as a modifier for both the Implementing alt mode as a sigil would add a lot of new complexity to the macros, though, which is not ideal. I think it might be worth trying to design a more general way to include any arbitrary format specifiers (such as, for example, format an integer in hexadecimal) without having to write |
What comes to my mind is a similar syntax as here: https://docs.rs/thiserror/1.0.24/thiserror/#details For example: let id = Uuid::new_v4();
tracing::debug!({id}, "New ID generated"); // {} prints as Display
tracing::debug!({id:?}, "New ID generated"); // {:?} prints as Debug
tracing::debug!({id:#}, "New ID generated"); // {:?} prints as Display alternate
// etc We could still retain a special case of: tracing::debug!(id, "New ID generated"); For using the regular |
Also need to support this in |
An arbitrary format syntax would be great, but I think "alternate mode" is the most important and it would be perfectly okay if we simply supported that and required The lack of support for |
Feature Request
Motivation
anyhow
provides a formatting of the whole error chain through the alternate selector{:#}
: https://docs.rs/anyhow/1.0.38/anyhow/struct.Error.html#display-representationsIt would be nice to make use of this within tracing events in a concise way.
Proposal
Add a formatter sigil (possibly
#
) to tracing that allows to print values using their alternateDisplay
implementation.For example:
Would print as:
Alternative
One can convert an anyhow error into a std-error. If reporting std-errors were to be made more ergonomic AND tracing provides a way of printing all causes of std-errors, then this feature is not needed. That being said, triggering the alternative
Display
impl is not specific to anyhow and might be useful in general.The text was updated successfully, but these errors were encountered: