Skip to content

Commit

Permalink
subscriber: skip padding when skipping log.* fields in `DefaultVisi…
Browse files Browse the repository at this point in the history
…tor` (#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
  • Loading branch information
Porges authored Dec 2, 2024
1 parent ce32540 commit b02a700
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions tracing-subscriber/src/fmt/format/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1238,12 +1238,20 @@ impl field::Visit for DefaultVisitor<'_> {
return;
}

let name = field.name();

// Skip fields that are actually log metadata that have already been handled
#[cfg(feature = "tracing-log")]
if name.starts_with("log.") {
debug_assert_eq!(self.result, Ok(())); // no need to update self.result
return;
}

// emit separating spaces if needed
self.maybe_pad();
self.result = match field.name() {

self.result = match name {
"message" => write!(self.writer, "{:?}", value),
// Skip fields that are actually log metadata that have already been handled
#[cfg(feature = "tracing-log")]
name if name.starts_with("log.") => Ok(()),
name if name.starts_with("r#") => write!(
self.writer,
"{}{}{:?}",
Expand Down

0 comments on commit b02a700

Please sign in to comment.