diff --git a/ecs-logging-core/src/main/java/co/elastic/logging/EcsJsonSerializer.java b/ecs-logging-core/src/main/java/co/elastic/logging/EcsJsonSerializer.java index deb77a15..8492e629 100644 --- a/ecs-logging-core/src/main/java/co/elastic/logging/EcsJsonSerializer.java +++ b/ecs-logging-core/src/main/java/co/elastic/logging/EcsJsonSerializer.java @@ -46,7 +46,7 @@ public static void serializeObjectStart(StringBuilder builder, long timeMillis) builder.append('{'); builder.append("\"@timestamp\":\""); TIMESTAMP_SERIALIZER.serializeEpochTimestampAsIsoDateTime(builder, timeMillis); - builder.append("\", "); + builder.append("\","); } public static void serializeEcsVersion(StringBuilder builder) { @@ -84,7 +84,7 @@ public static void serializeThreadId(StringBuilder builder, long threadId) { public static void serializeFormattedMessage(StringBuilder builder, String message) { builder.append("\"message\":\""); JsonUtils.quoteAsString(message, builder); - builder.append("\", "); + builder.append("\","); } public static void serializeServiceName(StringBuilder builder, String serviceName) { @@ -121,7 +121,7 @@ public static void serializeLogLevel(StringBuilder builder, String level) { } builder.append('\"'); JsonUtils.quoteAsString(level, builder); - builder.append("\", "); + builder.append("\","); } public static void serializeTag(StringBuilder builder, String tag) { diff --git a/ecs-logging-core/src/test/java/co/elastic/logging/AbstractEcsLoggingTest.java b/ecs-logging-core/src/test/java/co/elastic/logging/AbstractEcsLoggingTest.java index 8358570e..671acc3d 100644 --- a/ecs-logging-core/src/test/java/co/elastic/logging/AbstractEcsLoggingTest.java +++ b/ecs-logging-core/src/test/java/co/elastic/logging/AbstractEcsLoggingTest.java @@ -55,23 +55,27 @@ final void setUpSpec() throws Exception { @Test void testMetadata() throws Exception { debug("test"); - assertThat(getAndValidateLastLogLine().get("process.thread.name").textValue()).isEqualTo(Thread.currentThread().getName()); - assertThat(getAndValidateLastLogLine().get("service.name").textValue()).isEqualTo("test"); - assertThat(getAndValidateLastLogLine().get("service.node.name").textValue()).isEqualTo("test-node"); - assertThat(Instant.parse(getAndValidateLastLogLine().get("@timestamp").textValue())).isCloseTo(Instant.now(), within(1, ChronoUnit.MINUTES)); - assertThat(getAndValidateLastLogLine().get("log.level").textValue()).isIn("DEBUG", "FINE"); - assertThat(getAndValidateLastLogLine().get("log.logger")).isNotNull(); - assertThat(getAndValidateLastLogLine().get("event.dataset").textValue()).isEqualTo("testdataset"); - assertThat(getAndValidateLastLogLine().get("ecs.version").textValue()).isEqualTo("1.2.0"); - validateLog(getAndValidateLastLogLine()); + JsonNode logLine = getAndValidateLastLogLine(); + System.out.println(logLine.toPrettyString()); + assertThat(logLine.get("process.thread.name").textValue()).isEqualTo(Thread.currentThread().getName()); + assertThat(logLine.get("service.name").textValue()).isEqualTo("test"); + assertThat(logLine.get("service.node.name").textValue()).isEqualTo("test-node"); + assertThat(Instant.parse(logLine.get("@timestamp").textValue())).isCloseTo(Instant.now(), within(1, ChronoUnit.MINUTES)); + assertThat(logLine.get("log.level").textValue()).isIn("DEBUG", "FINE"); + assertThat(logLine.get("log.logger")).isNotNull(); + assertThat(logLine.get("event.dataset").textValue()).isEqualTo("testdataset"); + assertThat(logLine.get("ecs.version").textValue()).isEqualTo("1.2.0"); + validateLog(logLine); } @Test protected final void testAdditionalFields() throws Exception { debug("test"); - assertThat(getAndValidateLastLogLine().get("key1").textValue()).isEqualTo("value1"); - assertThat(getAndValidateLastLogLine().get("key2").textValue()).isEqualTo("value2"); - validateLog(getAndValidateLastLogLine()); + JsonNode logLine = getAndValidateLastLogLine(); + System.out.println(logLine.toPrettyString()); + assertThat(logLine.get("key1").textValue()).isEqualTo("value1"); + assertThat(logLine.get("key2").textValue()).isEqualTo("value2"); + validateLog(logLine); } @Test @@ -189,6 +193,7 @@ void testMdc() throws Exception { void testLogException() throws Exception { error("test", new RuntimeException("test")); JsonNode log = getAndValidateLastLogLine(); + System.out.println(log.toPrettyString()); assertThat(log.get("log.level").textValue()).isIn("ERROR", "SEVERE"); assertThat(log.get("error.message").textValue()).isEqualTo("test"); assertThat(log.get("error.type").textValue()).isEqualTo(RuntimeException.class.getName()); @@ -205,9 +210,11 @@ void testLogExceptionNullMessage() throws Exception { @Test void testLogOrigin() throws Exception { debug("test"); - assertThat(getAndValidateLastLogLine().at("/log/origin/file/name").textValue()).endsWith(".java"); - assertThat(getAndValidateLastLogLine().at("/log/origin/function").textValue()).isEqualTo("debug"); - assertThat(getAndValidateLastLogLine().at("/log/origin/file/line").intValue()).isPositive(); + JsonNode logLine = getAndValidateLastLogLine(); + System.out.println(logLine.toPrettyString()); + assertThat(logLine.at("/log/origin/file/name").textValue()).endsWith(".java"); + assertThat(logLine.at("/log/origin/function").textValue()).isEqualTo("debug"); + assertThat(logLine.at("/log/origin/file/line").intValue()).isPositive(); } public boolean putMdc(String key, String value) { diff --git a/ecs-logging-core/src/test/java/co/elastic/logging/EcsJsonSerializerTest.java b/ecs-logging-core/src/test/java/co/elastic/logging/EcsJsonSerializerTest.java index ec851e8a..0b96a38e 100644 --- a/ecs-logging-core/src/test/java/co/elastic/logging/EcsJsonSerializerTest.java +++ b/ecs-logging-core/src/test/java/co/elastic/logging/EcsJsonSerializerTest.java @@ -96,7 +96,7 @@ void testEscaping() throws IOException { void serializeNullDoesNotThrowAnException() throws JsonProcessingException { StringBuilder stringBuilder = new StringBuilder(); EcsJsonSerializer.serializeFormattedMessage(stringBuilder, null); - assertThat(stringBuilder.toString()).isEqualTo("\"message\":\"null\", "); + assertThat(stringBuilder.toString()).isEqualTo("\"message\":\"null\","); } @Test