From acb4447597a5e8897f9b80546f5fc1b4e56e0ea1 Mon Sep 17 00:00:00 2001 From: Felix Barnsteiner Date: Wed, 14 Aug 2019 14:50:37 +0200 Subject: [PATCH] Map logger name to log.logger instead of event.dataset see https://github.com/elastic/ecs/pull/521 closes #1 --- README.md | 6 +++--- .../src/main/java/co/elastic/logging/EcsJsonSerializer.java | 4 +--- .../java/co/elastic/logging/AbstractEcsLoggingTest.java | 1 + 3 files changed, 5 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 99609747..61800a4c 100644 --- a/README.md +++ b/README.md @@ -15,9 +15,9 @@ This library helps to log ECS-compatible JSON into a file Example: ``` -{"@timestamp":1565093352375,"service.name":"spring-petclinic","process.thread.name":"restartedMain","log.level":"INFO","event.dataset":"org.springframework.boot.web.embedded.tomcat.TomcatWebServer","message":"Tomcat started on port(s): 8080 (http) with context path ''"} -{"@timestamp":1565093352379,"service.name":"spring-petclinic","process.thread.name":"restartedMain","log.level":"INFO","event.dataset":"org.springframework.samples.petclinic.PetClinicApplication","message":"Started PetClinicApplication in 7.095 seconds (JVM running for 9.082)"} -{"@timestamp":1565100520199,"service.name":"spring-petclinic","process.thread.name":"http-nio-8080-exec-8","log.level":"INFO","event.dataset":"org.springframework.samples.petclinic.owner.OwnerController","transaction.id":"28b7fb8d5aba51f1","trace.id":"2869b25b5469590610fea49ac04af7da","message":"init find form"} +{"@timestamp":1565093352375,"service.name":"spring-petclinic","process.thread.name":"restartedMain","log.level":"INFO","log.logger":"org.springframework.boot.web.embedded.tomcat.TomcatWebServer","message":"Tomcat started on port(s): 8080 (http) with context path ''"} +{"@timestamp":1565093352379,"service.name":"spring-petclinic","process.thread.name":"restartedMain","log.level":"INFO","log.logger":"org.springframework.samples.petclinic.PetClinicApplication","message":"Started PetClinicApplication in 7.095 seconds (JVM running for 9.082)"} +{"@timestamp":1565100520199,"service.name":"spring-petclinic","process.thread.name":"http-nio-8080-exec-8","log.level":"INFO","log.logger":"org.springframework.samples.petclinic.owner.OwnerController","transaction.id":"28b7fb8d5aba51f1","trace.id":"2869b25b5469590610fea49ac04af7da","message":"init find form"} ``` ## Why ECS logging? 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 7093c76f..ebbbda27 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 @@ -3,8 +3,6 @@ import java.io.PrintWriter; import java.io.StringWriter; import java.util.Arrays; -import java.util.Collections; -import java.util.HashSet; import java.util.List; import java.util.Map; import java.util.Set; @@ -30,7 +28,7 @@ public static void serializeObjectEnd(StringBuilder builder) { } public static void serializeLoggerName(StringBuilder builder, String loggerName) { - builder.append("\"event.dataset\":\""); + builder.append("\"log.logger\":\""); JsonUtils.quoteAsString(loggerName, builder); builder.append("\","); } 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 5103aaaa..f03db749 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 @@ -23,6 +23,7 @@ void testMetadata() throws Exception { assertThat(getLastLogLine().get("service.name").textValue()).isEqualTo("test"); assertThat(getLastLogLine().get("@timestamp").longValue()).isGreaterThan(0); assertThat(getLastLogLine().get("log.level").textValue()).isEqualTo("DEBUG"); + assertThat(getLastLogLine().get("log.logger")).isNotNull(); } @Test