Skip to content

Commit

Permalink
feat(crowtty): put target after span context (#289)
Browse files Browse the repository at this point in the history
This makes it easier to see the span hierarchy based on indentation
levels. This is closer to the format used by `tracing-subscriber`, so
it also makes the format more familiar for tracing users.
  • Loading branch information
hawkw committed Sep 21, 2023
1 parent 3e7ca89 commit 416b7d5
Showing 1 changed file with 15 additions and 14 deletions.
29 changes: 15 additions & 14 deletions tools/crowtty/src/trace.rs
Original file line number Diff line number Diff line change
Expand Up @@ -199,19 +199,20 @@ impl TraceWorker {
}

let level = DisplayLevel(meta.level);
write!(&mut self.textbuf, "{} {level} ", self.state.tag,).unwrap();

if self.state.write_span_cx(&mut self.textbuf) {
self.textbuf.push(' ');
}

write!(
&mut self.textbuf,
"{} {level} {} ",
self.state.tag,
format_args!("{target}:")
"{}",
format_args!("{target}: ")
.if_supports_color(Stream::Stdout, |target| target.dimmed())
)
.unwrap();

if self.state.write_span_cx(&mut self.textbuf) {
self.textbuf.push(' ');
}

let SerializeRecordFields::De(ref fields) = fields else {
unreachable!("we are deserializing!");
};
Expand Down Expand Up @@ -347,17 +348,17 @@ impl FormatState {
repr,
..
} = span;
write!(textbuf, "{} {level} ", self.tag).unwrap();

self.write_span_cx(textbuf);

write!(
textbuf,
"{} {level} {} ",
self.tag,
format_args!("{}:", target).if_supports_color(Stream::Stdout, |target| target.dimmed())
"{repr}{target} {tag} ({id:04})",
target = format_args!(": {}:", target)
.if_supports_color(Stream::Stdout, |target| target.dimmed())
)
.unwrap();

self.write_span_cx(textbuf);

write!(textbuf, "{repr} {tag} ({id:04})").unwrap();
}

fn write_span_cx(&self, textbuf: &mut String) -> bool {
Expand Down

0 comments on commit 416b7d5

Please sign in to comment.