Skip to content

Commit

Permalink
subscriber: Add the closing } to the JSON logs (#415)
Browse files Browse the repository at this point in the history
## Motivation

JSON log lines are not correct JSON, the ending `}` is missing.

## Solution

Ending the `SerializeMap` correctly.
  • Loading branch information
Julius de Bruijn authored and hawkw committed Nov 5, 2019
1 parent e53df80 commit 72bffa2
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions tracing-subscriber/src/fmt/format/json.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,8 @@ where
serializer.serialize_entry("target", meta.target())?;
}

serializer.serialize_entry("fields", &event.field_map())
serializer.serialize_entry("fields", &event.field_map())?;
serializer.end()
};

visit().map_err(|_| fmt::Error)?;
Expand Down Expand Up @@ -264,7 +265,7 @@ mod test {
let make_writer = || MockWriter::new(&BUF);

let expected =
"{\"timestamp\":\"fake time\",\"level\":\"INFO\",\"span\":{\"name\":\"json_span\",\"fields\":\"{\\\"answer\\\":42,\\\"number\\\":3}\"},\"target\":\"tracing_subscriber::fmt::format::json::test\",\"fields\":{\"message\":\"some json test\"}\n";
"{\"timestamp\":\"fake time\",\"level\":\"INFO\",\"span\":{\"name\":\"json_span\",\"fields\":\"{\\\"answer\\\":42,\\\"number\\\":3}\"},\"target\":\"tracing_subscriber::fmt::format::json::test\",\"fields\":{\"message\":\"some json test\"}}\n";

test_json(make_writer, expected, &BUF);
}
Expand Down

0 comments on commit 72bffa2

Please sign in to comment.