Skip to content

Commit

Permalink
Fix formatting for space indented mode
Browse files Browse the repository at this point in the history
  • Loading branch information
oli-obk committed May 23, 2023
1 parent 458e9b2 commit 4703a59
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 6 deletions.
8 changes: 7 additions & 1 deletion src/format.rs
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,7 @@ impl Buffers {

pub struct FmtEvent<'a> {
pub bufs: &'a mut Buffers,
pub lines: bool,
}

impl<'a> Visit for FmtEvent<'a> {
Expand All @@ -235,7 +236,12 @@ impl<'a> Visit for FmtEvent<'a> {
#[cfg(feature = "tracing-log")]
name if name.starts_with("log.") => {}
name => {
write!(buf, "\n {}={:?}", name, value).unwrap();
if self.lines {
write!(buf, "\n ").unwrap()
} else {
write!(buf, ", ").unwrap()
}
write!(buf, "{}={:?}", name, value).unwrap();
}
}
}
Expand Down
15 changes: 10 additions & 5 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -212,16 +212,18 @@ where
V: fmt::Display + 'a,
{
let mut kvs = kvs.into_iter();
let nl = if self.config.bracketed_fields {
""
let (nl, first) = if self.config.bracketed_fields {
("", "")
} else if self.config.indent_lines {
("\n ", "\n ")
} else {
"\n "
(", ", " ")
};
if let Some((k, v)) = kvs.next() {
if k == "message" {
write!(buf, " {}", v)?;
} else {
write!(buf, "{nl}{}={}", k, v)?;
write!(buf, "{first}{}={}", k, v)?;
}
}
for (k, v) in kvs {
Expand Down Expand Up @@ -412,7 +414,10 @@ where
.expect("Unable to write to buffer");
}

let mut visitor = FmtEvent { bufs };
let mut visitor = FmtEvent {
bufs,
lines: self.config.indent_lines,
};
event.record(&mut visitor);
visitor
.bufs
Expand Down

0 comments on commit 4703a59

Please sign in to comment.