Skip to content

Commit

Permalink
Support for Logback 1.1 (#88)
Browse files Browse the repository at this point in the history
  • Loading branch information
felixbarny committed Oct 30, 2020
1 parent 4f9fd22 commit d729141
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 1 deletion.
2 changes: 1 addition & 1 deletion logback-ecs-encoder/README.md
Original file line number Diff line number Diff line change
@@ -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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -48,6 +50,7 @@ public class EcsEncoder extends EncoderBase<ILoggingEvent> {
private ThrowableProxyConverter throwableProxyConverter;
private boolean includeOrigin;
private final List<Pair> additionalFields = new ArrayList<Pair>();
private OutputStream os;

@Override
public byte[] headerBytes() {
Expand All @@ -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) {
Expand Down

0 comments on commit d729141

Please sign in to comment.