Skip to content

Commit

Permalink
Remove brackets and message field name from rendered message
Browse files Browse the repository at this point in the history
  • Loading branch information
oli-obk committed Aug 18, 2020
1 parent c46446b commit 19a23fc
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 25 deletions.
12 changes: 11 additions & 1 deletion examples/basic.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use tracing::{debug, info, instrument, span, warn, Level};
use tracing::{debug, error, info, instrument, span, warn, Level};
use tracing_subscriber::{layer::SubscriberExt, registry::Registry};
use tracing_tree::HierarchicalLayer;

Expand Down Expand Up @@ -34,6 +34,16 @@ fn main() {
std::thread::sleep(std::time::Duration::from_millis(300));
debug!("connected");
});
let peer3 = span!(
Level::TRACE,
"foomp",
normal_var = 43,
"{} <- format string",
42
);
peer3.in_scope(|| {
error!("hello");
});
peer1.in_scope(|| {
warn!(algo = "xor", "weak encryption requested");
std::thread::sleep(std::time::Duration::from_millis(300));
Expand Down
34 changes: 10 additions & 24 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -177,23 +177,21 @@ where
}
}

fn print_kvs<'a, I, K, V>(
&self,
buf: &mut impl fmt::Write,
kvs: I,
leading: &str,
) -> fmt::Result
fn print_kvs<'a, I, V>(&self, buf: &mut impl fmt::Write, kvs: I) -> fmt::Result
where
I: IntoIterator<Item = (K, V)>,
K: AsRef<str> + 'a,
I: IntoIterator<Item = (&'a str, V)>,
V: fmt::Display + 'a,
{
let mut kvs = kvs.into_iter();
if let Some((k, v)) = kvs.next() {
write!(buf, "{}{}={}", leading, k.as_ref(), v)?;
if k == "message" {
write!(buf, "{}", v)?;
} else {
write!(buf, "{}={}", k, v)?;
}
}
for (k, v) in kvs {
write!(buf, ", {}={}", k.as_ref(), v)?;
write!(buf, ", {}={}", k, v)?;
}
Ok(())
}
Expand Down Expand Up @@ -234,24 +232,12 @@ where

write!(
current_buf,
"{name}",
"{name} ",
name = self.styled(Style::new().fg(Color::Green).bold(), span.metadata().name())
)
.unwrap();
write!(
current_buf,
"{}",
self.styled(Style::new().fg(Color::Green).bold(), "{") // Style::new().fg(Color::Green).dimmed().paint("{")
)
.unwrap();
self.print_kvs(&mut current_buf, data.kvs.iter().map(|(k, v)| (k, v)), "")
self.print_kvs(&mut current_buf, data.kvs.iter().map(|(k, v)| (*k, v)))
.unwrap();
write!(
current_buf,
"{}",
self.styled(Style::new().fg(Color::Green).bold(), "}") // Style::new().dimmed().paint("}")
)
.unwrap();

bufs.indent_current(indent, &self.config, style);
let writer = self.make_writer.make_writer();
Expand Down

0 comments on commit 19a23fc

Please sign in to comment.