diff --git a/logback-ecs-encoder/README.md b/logback-ecs-encoder/README.md index 3980df8b..c2463b29 100644 --- a/logback-ecs-encoder/README.md +++ b/logback-ecs-encoder/README.md @@ -1,6 +1,6 @@ # ECS Logback Encoder -The minimum required logback version is 1.2. +The minimum required logback version is 1.1. ## Step 1: add dependency diff --git a/logback-ecs-encoder/src/main/java/co/elastic/logging/logback/EcsEncoder.java b/logback-ecs-encoder/src/main/java/co/elastic/logging/logback/EcsEncoder.java index f8a144ae..b009e9e6 100644 --- a/logback-ecs-encoder/src/main/java/co/elastic/logging/logback/EcsEncoder.java +++ b/logback-ecs-encoder/src/main/java/co/elastic/logging/logback/EcsEncoder.java @@ -33,6 +33,8 @@ import co.elastic.logging.JsonUtils; import org.slf4j.Marker; +import java.io.IOException; +import java.io.OutputStream; import java.nio.charset.Charset; import java.util.ArrayList; import java.util.Iterator; @@ -48,6 +50,7 @@ public class EcsEncoder extends EncoderBase { private ThrowableProxyConverter throwableProxyConverter; private boolean includeOrigin; private final List additionalFields = new ArrayList(); + private OutputStream os; @Override public byte[] headerBytes() { @@ -61,6 +64,28 @@ public void start() { throwableProxyConverter.start(); eventDataset = EcsJsonSerializer.computeEventDataset(eventDataset, serviceName); } + /** + * This method has been removed in logback 1.2. + * To make this lib backwards compatible with logback 1.1 we have implement this method. + */ + public void init(OutputStream os) { + this.os = os; + } + + /** + * This method has been removed in logback 1.2. + * To make this lib backwards compatible with logback 1.1 we have implement this method. + */ + public void doEncode(ILoggingEvent event) throws IOException { + os.write(encode(event)); + } + + /** + * This method has been removed in logback 1.2. + * To make this lib backwards compatible with logback 1.1 we have implement this method. + */ + public void close() throws IOException { + } @Override public byte[] encode(ILoggingEvent event) {