Skip to content

Commit b02a700

Browse files
authored
subscriber: skip padding when skipping log.* fields in DefaultVisitor (#2980)
## Motivation The current behaviour of `DefaultVisitor` is that it will write padding even if it is going to skip writing a value, which results in extraneous padding being added when values are skipped by the `tracing-log` integration. ## Solution With this change, `DefaultVisitor` will only insert padding if it is actually going to write a value. Closes: #2979
1 parent ce32540 commit b02a700

File tree

1 file changed

+12
-4
lines changed
  • tracing-subscriber/src/fmt/format

1 file changed

+12
-4
lines changed

tracing-subscriber/src/fmt/format/mod.rs

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1238,12 +1238,20 @@ impl field::Visit for DefaultVisitor<'_> {
12381238
return;
12391239
}
12401240

1241+
let name = field.name();
1242+
1243+
// Skip fields that are actually log metadata that have already been handled
1244+
#[cfg(feature = "tracing-log")]
1245+
if name.starts_with("log.") {
1246+
debug_assert_eq!(self.result, Ok(())); // no need to update self.result
1247+
return;
1248+
}
1249+
1250+
// emit separating spaces if needed
12411251
self.maybe_pad();
1242-
self.result = match field.name() {
1252+
1253+
self.result = match name {
12431254
"message" => write!(self.writer, "{:?}", value),
1244-
// Skip fields that are actually log metadata that have already been handled
1245-
#[cfg(feature = "tracing-log")]
1246-
name if name.starts_with("log.") => Ok(()),
12471255
name if name.starts_with("r#") => write!(
12481256
self.writer,
12491257
"{}{}{:?}",

0 commit comments

Comments
 (0)