diff --git a/logback-ecs-encoder/pom.xml b/logback-ecs-encoder/pom.xml index 8301c1c2..c8de0b92 100644 --- a/logback-ecs-encoder/pom.xml +++ b/logback-ecs-encoder/pom.xml @@ -14,6 +14,23 @@ ${project.basedir}/.. + + + + org.apache.maven.plugins + maven-jar-plugin + 3.1.2 + + + + test-jar + + + + + + + ${project.groupId} 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 87a018e8..530d2820 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 @@ -75,9 +75,14 @@ public void init(OutputStream 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. + * However, since we compile with 1.2.x, this method is not compiled as an interface method, which means that there won't be type + * erasure. Therefore, we must use a {@link Object} argument for it to be compatible with 1.1.x. */ - public void doEncode(ILoggingEvent event) throws IOException { - os.write(encode(event)); + public void doEncode(Object event) throws IOException { + os.write(encode((ILoggingEvent) event)); + // on logback 1.1.x versions this encoder always works as if immediateFlush == true. In later versions, flushing is only handled by + // the appender rather than the encoder + os.flush(); } /** diff --git a/logback-ecs-encoder/src/test/java/co/elastic/logging/logback/EcsEncoderIntegrationTest.java b/logback-ecs-encoder/src/test/java/co/elastic/logging/logback/EcsEncoderIntegrationTest.java index 1a3bf444..a4ef1923 100644 --- a/logback-ecs-encoder/src/test/java/co/elastic/logging/logback/EcsEncoderIntegrationTest.java +++ b/logback-ecs-encoder/src/test/java/co/elastic/logging/logback/EcsEncoderIntegrationTest.java @@ -32,7 +32,7 @@ import java.io.IOException; -class EcsEncoderIntegrationTest extends AbstractEcsEncoderTest { +public class EcsEncoderIntegrationTest extends AbstractEcsEncoderTest { private OutputStreamAppender appender; @BeforeEach diff --git a/logback-ecs-encoder/src/test/java/co/elastic/logging/logback/EcsEncoderTest.java b/logback-ecs-encoder/src/test/java/co/elastic/logging/logback/EcsEncoderTest.java index 6285e53c..e8f915ae 100644 --- a/logback-ecs-encoder/src/test/java/co/elastic/logging/logback/EcsEncoderTest.java +++ b/logback-ecs-encoder/src/test/java/co/elastic/logging/logback/EcsEncoderTest.java @@ -31,7 +31,7 @@ import java.io.IOException; -class EcsEncoderTest extends AbstractEcsEncoderTest { +public class EcsEncoderTest extends AbstractEcsEncoderTest { private OutputStreamAppender appender; diff --git a/logback-legacy-tests/pom.xml b/logback-legacy-tests/pom.xml new file mode 100644 index 00000000..bfe04bdb --- /dev/null +++ b/logback-legacy-tests/pom.xml @@ -0,0 +1,46 @@ + + + + ecs-logging-java-parent + co.elastic.logging + 1.0.1-SNAPSHOT + + 4.0.0 + + logback-legacy-tests + + + ${project.basedir}/.. + true + + + + + ${project.groupId} + ecs-logging-core + ${project.version} + test-jar + test + + + ${project.groupId} + logback-ecs-encoder + ${project.version} + test + + + ${project.groupId} + logback-ecs-encoder + ${project.version} + test-jar + test + + + ch.qos.logback + logback-classic + 1.1.0 + test + + + + \ No newline at end of file diff --git a/logback-legacy-tests/src/test/java/co/elastic/logging/logback/LegacyEcsEncoderIntegrationTest.java b/logback-legacy-tests/src/test/java/co/elastic/logging/logback/LegacyEcsEncoderIntegrationTest.java new file mode 100644 index 00000000..164764b7 --- /dev/null +++ b/logback-legacy-tests/src/test/java/co/elastic/logging/logback/LegacyEcsEncoderIntegrationTest.java @@ -0,0 +1,29 @@ +/*- + * #%L + * Java ECS logging + * %% + * Copyright (C) 2019 - 2020 Elastic and contributors + * %% + * Licensed to Elasticsearch B.V. under one or more contributor + * license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright + * ownership. Elasticsearch B.V. licenses this file to you under + * the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + * #L% + */ +package co.elastic.logging.logback; + +class LegacyEcsEncoderIntegrationTest extends EcsEncoderIntegrationTest { + +} diff --git a/logback-legacy-tests/src/test/java/co/elastic/logging/logback/LegacyEcsEncoderTest.java b/logback-legacy-tests/src/test/java/co/elastic/logging/logback/LegacyEcsEncoderTest.java new file mode 100644 index 00000000..75bdf93b --- /dev/null +++ b/logback-legacy-tests/src/test/java/co/elastic/logging/logback/LegacyEcsEncoderTest.java @@ -0,0 +1,29 @@ +/*- + * #%L + * Java ECS logging + * %% + * Copyright (C) 2019 - 2020 Elastic and contributors + * %% + * Licensed to Elasticsearch B.V. under one or more contributor + * license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright + * ownership. Elasticsearch B.V. licenses this file to you under + * the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + * #L% + */ +package co.elastic.logging.logback; + +class LegacyEcsEncoderTest extends EcsEncoderTest { + +} diff --git a/pom.xml b/pom.xml index 531796bb..7c6ffd24 100644 --- a/pom.xml +++ b/pom.xml @@ -15,6 +15,7 @@ jboss-logmanager-ecs-formatter log4j2-legacy-tests log4j-legacy-tests + logback-legacy-tests pom 2019