Skip to content

Commit 775556e

Browse files
authored
Remove trailing space from serialization (#180)
1 parent 23d5bd6 commit 775556e

File tree

3 files changed

+26
-19
lines changed

3 files changed

+26
-19
lines changed

ecs-logging-core/src/main/java/co/elastic/logging/EcsJsonSerializer.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ public static void serializeObjectStart(StringBuilder builder, long timeMillis)
4646
builder.append('{');
4747
builder.append("\"@timestamp\":\"");
4848
TIMESTAMP_SERIALIZER.serializeEpochTimestampAsIsoDateTime(builder, timeMillis);
49-
builder.append("\", ");
49+
builder.append("\",");
5050
}
5151

5252
public static void serializeEcsVersion(StringBuilder builder) {
@@ -84,7 +84,7 @@ public static void serializeThreadId(StringBuilder builder, long threadId) {
8484
public static void serializeFormattedMessage(StringBuilder builder, String message) {
8585
builder.append("\"message\":\"");
8686
JsonUtils.quoteAsString(message, builder);
87-
builder.append("\", ");
87+
builder.append("\",");
8888
}
8989

9090
public static void serializeServiceName(StringBuilder builder, String serviceName) {
@@ -121,7 +121,7 @@ public static void serializeLogLevel(StringBuilder builder, String level) {
121121
}
122122
builder.append('\"');
123123
JsonUtils.quoteAsString(level, builder);
124-
builder.append("\", ");
124+
builder.append("\",");
125125
}
126126

127127
public static void serializeTag(StringBuilder builder, String tag) {

ecs-logging-core/src/test/java/co/elastic/logging/AbstractEcsLoggingTest.java

Lines changed: 22 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -55,23 +55,27 @@ final void setUpSpec() throws Exception {
5555
@Test
5656
void testMetadata() throws Exception {
5757
debug("test");
58-
assertThat(getAndValidateLastLogLine().get("process.thread.name").textValue()).isEqualTo(Thread.currentThread().getName());
59-
assertThat(getAndValidateLastLogLine().get("service.name").textValue()).isEqualTo("test");
60-
assertThat(getAndValidateLastLogLine().get("service.node.name").textValue()).isEqualTo("test-node");
61-
assertThat(Instant.parse(getAndValidateLastLogLine().get("@timestamp").textValue())).isCloseTo(Instant.now(), within(1, ChronoUnit.MINUTES));
62-
assertThat(getAndValidateLastLogLine().get("log.level").textValue()).isIn("DEBUG", "FINE");
63-
assertThat(getAndValidateLastLogLine().get("log.logger")).isNotNull();
64-
assertThat(getAndValidateLastLogLine().get("event.dataset").textValue()).isEqualTo("testdataset");
65-
assertThat(getAndValidateLastLogLine().get("ecs.version").textValue()).isEqualTo("1.2.0");
66-
validateLog(getAndValidateLastLogLine());
58+
JsonNode logLine = getAndValidateLastLogLine();
59+
System.out.println(logLine.toPrettyString());
60+
assertThat(logLine.get("process.thread.name").textValue()).isEqualTo(Thread.currentThread().getName());
61+
assertThat(logLine.get("service.name").textValue()).isEqualTo("test");
62+
assertThat(logLine.get("service.node.name").textValue()).isEqualTo("test-node");
63+
assertThat(Instant.parse(logLine.get("@timestamp").textValue())).isCloseTo(Instant.now(), within(1, ChronoUnit.MINUTES));
64+
assertThat(logLine.get("log.level").textValue()).isIn("DEBUG", "FINE");
65+
assertThat(logLine.get("log.logger")).isNotNull();
66+
assertThat(logLine.get("event.dataset").textValue()).isEqualTo("testdataset");
67+
assertThat(logLine.get("ecs.version").textValue()).isEqualTo("1.2.0");
68+
validateLog(logLine);
6769
}
6870

6971
@Test
7072
protected final void testAdditionalFields() throws Exception {
7173
debug("test");
72-
assertThat(getAndValidateLastLogLine().get("key1").textValue()).isEqualTo("value1");
73-
assertThat(getAndValidateLastLogLine().get("key2").textValue()).isEqualTo("value2");
74-
validateLog(getAndValidateLastLogLine());
74+
JsonNode logLine = getAndValidateLastLogLine();
75+
System.out.println(logLine.toPrettyString());
76+
assertThat(logLine.get("key1").textValue()).isEqualTo("value1");
77+
assertThat(logLine.get("key2").textValue()).isEqualTo("value2");
78+
validateLog(logLine);
7579
}
7680

7781
@Test
@@ -189,6 +193,7 @@ void testMdc() throws Exception {
189193
void testLogException() throws Exception {
190194
error("test", new RuntimeException("test"));
191195
JsonNode log = getAndValidateLastLogLine();
196+
System.out.println(log.toPrettyString());
192197
assertThat(log.get("log.level").textValue()).isIn("ERROR", "SEVERE");
193198
assertThat(log.get("error.message").textValue()).isEqualTo("test");
194199
assertThat(log.get("error.type").textValue()).isEqualTo(RuntimeException.class.getName());
@@ -205,9 +210,11 @@ void testLogExceptionNullMessage() throws Exception {
205210
@Test
206211
void testLogOrigin() throws Exception {
207212
debug("test");
208-
assertThat(getAndValidateLastLogLine().at("/log/origin/file/name").textValue()).endsWith(".java");
209-
assertThat(getAndValidateLastLogLine().at("/log/origin/function").textValue()).isEqualTo("debug");
210-
assertThat(getAndValidateLastLogLine().at("/log/origin/file/line").intValue()).isPositive();
213+
JsonNode logLine = getAndValidateLastLogLine();
214+
System.out.println(logLine.toPrettyString());
215+
assertThat(logLine.at("/log/origin/file/name").textValue()).endsWith(".java");
216+
assertThat(logLine.at("/log/origin/function").textValue()).isEqualTo("debug");
217+
assertThat(logLine.at("/log/origin/file/line").intValue()).isPositive();
211218
}
212219

213220
public boolean putMdc(String key, String value) {

ecs-logging-core/src/test/java/co/elastic/logging/EcsJsonSerializerTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ void testEscaping() throws IOException {
9696
void serializeNullDoesNotThrowAnException() throws JsonProcessingException {
9797
StringBuilder stringBuilder = new StringBuilder();
9898
EcsJsonSerializer.serializeFormattedMessage(stringBuilder, null);
99-
assertThat(stringBuilder.toString()).isEqualTo("\"message\":\"null\", ");
99+
assertThat(stringBuilder.toString()).isEqualTo("\"message\":\"null\",");
100100
}
101101

102102
@Test

0 commit comments

Comments
 (0)