From 72bffa2d4fbd2a24316713a7984a8ab48eafa040 Mon Sep 17 00:00:00 2001 From: Julius de Bruijn Date: Tue, 5 Nov 2019 21:17:48 +0000 Subject: [PATCH] subscriber: Add the closing } to the JSON logs (#415) ## Motivation JSON log lines are not correct JSON, the ending `}` is missing. ## Solution Ending the `SerializeMap` correctly. --- tracing-subscriber/src/fmt/format/json.rs | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/tracing-subscriber/src/fmt/format/json.rs b/tracing-subscriber/src/fmt/format/json.rs index 9f16882cb6..34036a5ed8 100644 --- a/tracing-subscriber/src/fmt/format/json.rs +++ b/tracing-subscriber/src/fmt/format/json.rs @@ -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)?; @@ -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); }