Skip to content

Commit

Permalink
Serialize field "payload" before field "tid"
Browse files Browse the repository at this point in the history
  • Loading branch information
SpriteOvO committed Aug 5, 2024
1 parent 11df475 commit 10f17d3
Showing 1 changed file with 5 additions and 6 deletions.
11 changes: 5 additions & 6 deletions spdlog/src/formatter/json_formatter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,8 @@ impl<'a> Serialize for JsonRecord<'a> {
.and_then(|dur| u64::try_from(dur.as_millis()).ok())
.expect("invalid timestamp"),
)?;
record.serialize_field("tid", &self.0.tid())?;
record.serialize_field("payload", self.0.payload())?;

record.serialize_field("tid", &self.0.tid())?;
if let Some(src_loc) = src_loc {
record.serialize_field("source", src_loc)?;
}
Expand Down Expand Up @@ -156,10 +155,10 @@ mod tests {
assert_eq!(
dest.to_string(),
format!(
r#"{{"level":"Info","timestamp":{},"tid":{},"payload":"{}"}}{}"#,
r#"{{"level":"Info","timestamp":{},"payload":"{}","tid":{}}}{}"#,
local_time.timestamp_millis(),
record.tid(),
"payload",
record.tid(),
__EOL
)
);
Expand All @@ -180,10 +179,10 @@ mod tests {
assert_eq!(
dest.to_string(),
format!(
r#"{{"level":"Info","timestamp":{},"tid":{},"payload":"{}","source":{{"module_path":"module","file":"file.rs","line":1,"column":2}}}}{}"#,
r#"{{"level":"Info","timestamp":{},"payload":"{}","tid":{},"source":{{"module_path":"module","file":"file.rs","line":1,"column":2}}}}{}"#,
local_time.timestamp_millis(),
record.tid(),
"payload",
record.tid(),
__EOL
)
);
Expand Down

0 comments on commit 10f17d3

Please sign in to comment.