From 05a4dc12d8fc6d911b1c8058bb9e3779c443c6c6 Mon Sep 17 00:00:00 2001 From: Thayne McCombs Date: Mon, 4 Apr 2022 01:36:26 -0600 Subject: [PATCH] Write key-value pairs after target --- src/fmt/mod.rs | 36 +++++++++++++++++++++++++++++++++++- 1 file changed, 35 insertions(+), 1 deletion(-) diff --git a/src/fmt/mod.rs b/src/fmt/mod.rs index 6d9c8d16..c0d79094 100644 --- a/src/fmt/mod.rs +++ b/src/fmt/mod.rs @@ -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) @@ -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); + } }