Skip to content

Commit

Permalink
Write key-value pairs after target
Browse files Browse the repository at this point in the history
  • Loading branch information
tmccombs committed May 4, 2023
1 parent 748a9ea commit 05a4dc1
Showing 1 changed file with 35 additions and 1 deletion.
36 changes: 35 additions & 1 deletion src/fmt/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -247,8 +247,8 @@ impl<'a> DefaultFormat<'a> {
self.write_timestamp()?;
self.write_level(record)?;
self.write_module_path(record)?;
self.write_kv(record)?;
self.write_target(record)?;
self.write_kv(record)?;
self.finish_header()?;

self.write_args(record)
Expand Down Expand Up @@ -714,4 +714,38 @@ mod tests {
#[cfg(feature = "kv_unstable")]
assert_eq!("[INFO a=1 b=2] log\nmessage\n", written);
}

#[cfg(feature = "kv_unstable")]
#[test]
fn format_kv_full() {
let kvs = &[("a", 1u32), ("b", 2u32)][..];
let mut f = formatter();
let record = Record::builder()
.args(format_args!("log\nmessage"))
.level(Level::Info)
.module_path(Some("test::path"))
.target("target")
.file(Some("test.rs"))
.line(Some(42))
.key_values(&kvs)
.build();

let written = write_record(
record,
DefaultFormat {
timestamp: None,
module_path: true,
target: true,
level: true,
key_values: true,
written_header_value: false,
indent: None,
suffix: "\n",
buf: &mut f,
},
);

#[cfg(feature = "kv_unstable")]
assert_eq!("[INFO test::path target a=1 b=2] log\nmessage\n", written);
}
}

0 comments on commit 05a4dc1

Please sign in to comment.