diff --git a/tracing-core/src/field.rs b/tracing-core/src/field.rs index b62e91e235..b621a94ae5 100644 --- a/tracing-core/src/field.rs +++ b/tracing-core/src/field.rs @@ -301,7 +301,7 @@ pub trait Visit { #[cfg(feature = "std")] #[cfg_attr(docsrs, doc(cfg(feature = "std")))] fn record_error(&mut self, field: &Field, value: &(dyn std::error::Error + 'static)) { - self.record_debug(field, &format_args!("{}", value)) + self.record_debug(field, &DisplayValue(value)) } /// Visit a value implementing `fmt::Debug`. @@ -599,19 +599,19 @@ where T: fmt::Display, { fn record(&self, key: &Field, visitor: &mut dyn Visit) { - visitor.record_debug(key, &format_args!("{}", self.0)) + visitor.record_debug(key, self) } } impl fmt::Debug for DisplayValue { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { - write!(f, "{}", self.0) + fmt::Display::fmt(self, f) } } impl fmt::Display for DisplayValue { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { - fmt::Display::fmt(&self.0, f) + self.0.fmt(f) } } @@ -630,7 +630,7 @@ where impl fmt::Debug for DebugValue { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { - write!(f, "{:?}", self.0) + self.0.fmt(f) } }