Skip to content

Commit de8cdbe

Browse files
committed
Set Jackson default root value separator to an empty String
JsonGenerator are now reused instead of creating a new one every time. The consequence is the same JsonGenerator is used to serialize multiple events as "root" object. This commit forces the default root value separator to empty string to avoid extra padding between log events.
1 parent 7dd9e15 commit de8cdbe

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

src/main/java/net/logstash/logback/composite/AbstractCompositeJsonFormatter.java

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030

3131
import ch.qos.logback.access.spi.IAccessEvent;
3232
import ch.qos.logback.classic.spi.ILoggingEvent;
33+
import ch.qos.logback.core.CoreConstants;
3334
import ch.qos.logback.core.spi.ContextAware;
3435
import ch.qos.logback.core.spi.ContextAwareBase;
3536
import ch.qos.logback.core.spi.DeferredProcessingAware;
@@ -39,6 +40,7 @@
3940
import com.fasterxml.jackson.core.JsonFactory;
4041
import com.fasterxml.jackson.core.JsonFactory.Feature;
4142
import com.fasterxml.jackson.core.JsonGenerator;
43+
import com.fasterxml.jackson.core.io.SerializedString;
4244
import com.fasterxml.jackson.databind.ObjectMapper;
4345
import com.fasterxml.jackson.databind.SerializationFeature;
4446

@@ -300,7 +302,14 @@ private JsonGenerator decorateGenerator(JsonGenerator generator) {
300302
* Don't let the json generator close the underlying outputStream and let the
301303
* encoder managed it.
302304
*/
303-
.disable(JsonGenerator.Feature.AUTO_CLOSE_TARGET);
305+
.disable(JsonGenerator.Feature.AUTO_CLOSE_TARGET)
306+
307+
/*
308+
* JsonGenerator are reused to serialize multiple log events.
309+
* Change the default roo tvalue separator to an empty string.
310+
*/
311+
.setRootValueSeparator(new SerializedString(CoreConstants.EMPTY_STRING));
312+
304313
}
305314

306315
public JsonFactory getJsonFactory() {

0 commit comments

Comments
 (0)