Skip to content

Commit b7c2e21

Browse files
authored
Fixing Logback 1.1 support and add legacy tests (#122)
1 parent f0c9be3 commit b7c2e21

File tree

8 files changed

+131
-4
lines changed

8 files changed

+131
-4
lines changed

logback-ecs-encoder/pom.xml

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,23 @@
1414
<parent.base.dir>${project.basedir}/..</parent.base.dir>
1515
</properties>
1616

17+
<build>
18+
<plugins>
19+
<plugin>
20+
<groupId>org.apache.maven.plugins</groupId>
21+
<artifactId>maven-jar-plugin</artifactId>
22+
<version>3.1.2</version>
23+
<executions>
24+
<execution>
25+
<goals>
26+
<goal>test-jar</goal>
27+
</goals>
28+
</execution>
29+
</executions>
30+
</plugin>
31+
</plugins>
32+
</build>
33+
1734
<dependencies>
1835
<dependency>
1936
<groupId>${project.groupId}</groupId>

logback-ecs-encoder/src/main/java/co/elastic/logging/logback/EcsEncoder.java

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,9 +75,14 @@ public void init(OutputStream os) {
7575
/**
7676
* This method has been removed in logback 1.2.
7777
* To make this lib backwards compatible with logback 1.1 we have implement this method.
78+
* 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
79+
* erasure. Therefore, we must use a {@link Object} argument for it to be compatible with 1.1.x.
7880
*/
79-
public void doEncode(ILoggingEvent event) throws IOException {
80-
os.write(encode(event));
81+
public void doEncode(Object event) throws IOException {
82+
os.write(encode((ILoggingEvent) event));
83+
// on logback 1.1.x versions this encoder always works as if immediateFlush == true. In later versions, flushing is only handled by
84+
// the appender rather than the encoder
85+
os.flush();
8186
}
8287

8388
/**

logback-ecs-encoder/src/test/java/co/elastic/logging/logback/EcsEncoderIntegrationTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232

3333
import java.io.IOException;
3434

35-
class EcsEncoderIntegrationTest extends AbstractEcsEncoderTest {
35+
public class EcsEncoderIntegrationTest extends AbstractEcsEncoderTest {
3636
private OutputStreamAppender appender;
3737

3838
@BeforeEach

logback-ecs-encoder/src/test/java/co/elastic/logging/logback/EcsEncoderTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131

3232
import java.io.IOException;
3333

34-
class EcsEncoderTest extends AbstractEcsEncoderTest {
34+
public class EcsEncoderTest extends AbstractEcsEncoderTest {
3535

3636
private OutputStreamAppender appender;
3737

logback-legacy-tests/pom.xml

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
3+
<parent>
4+
<artifactId>ecs-logging-java-parent</artifactId>
5+
<groupId>co.elastic.logging</groupId>
6+
<version>1.0.1-SNAPSHOT</version>
7+
</parent>
8+
<modelVersion>4.0.0</modelVersion>
9+
10+
<artifactId>logback-legacy-tests</artifactId>
11+
12+
<properties>
13+
<parent.base.dir>${project.basedir}/..</parent.base.dir>
14+
<maven-deploy-plugin.skip>true</maven-deploy-plugin.skip>
15+
</properties>
16+
17+
<dependencies>
18+
<dependency>
19+
<groupId>${project.groupId}</groupId>
20+
<artifactId>ecs-logging-core</artifactId>
21+
<version>${project.version}</version>
22+
<type>test-jar</type>
23+
<scope>test</scope>
24+
</dependency>
25+
<dependency>
26+
<groupId>${project.groupId}</groupId>
27+
<artifactId>logback-ecs-encoder</artifactId>
28+
<version>${project.version}</version>
29+
<scope>test</scope>
30+
</dependency>
31+
<dependency>
32+
<groupId>${project.groupId}</groupId>
33+
<artifactId>logback-ecs-encoder</artifactId>
34+
<version>${project.version}</version>
35+
<type>test-jar</type>
36+
<scope>test</scope>
37+
</dependency>
38+
<dependency>
39+
<groupId>ch.qos.logback</groupId>
40+
<artifactId>logback-classic</artifactId>
41+
<version>1.1.0</version>
42+
<scope>test</scope>
43+
</dependency>
44+
</dependencies>
45+
46+
</project>
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
/*-
2+
* #%L
3+
* Java ECS logging
4+
* %%
5+
* Copyright (C) 2019 - 2020 Elastic and contributors
6+
* %%
7+
* Licensed to Elasticsearch B.V. under one or more contributor
8+
* license agreements. See the NOTICE file distributed with
9+
* this work for additional information regarding copyright
10+
* ownership. Elasticsearch B.V. licenses this file to you under
11+
* the Apache License, Version 2.0 (the "License"); you may
12+
* not use this file except in compliance with the License.
13+
* You may obtain a copy of the License at
14+
*
15+
* http://www.apache.org/licenses/LICENSE-2.0
16+
*
17+
* Unless required by applicable law or agreed to in writing,
18+
* software distributed under the License is distributed on an
19+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
20+
* KIND, either express or implied. See the License for the
21+
* specific language governing permissions and limitations
22+
* under the License.
23+
* #L%
24+
*/
25+
package co.elastic.logging.logback;
26+
27+
class LegacyEcsEncoderIntegrationTest extends EcsEncoderIntegrationTest {
28+
29+
}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
/*-
2+
* #%L
3+
* Java ECS logging
4+
* %%
5+
* Copyright (C) 2019 - 2020 Elastic and contributors
6+
* %%
7+
* Licensed to Elasticsearch B.V. under one or more contributor
8+
* license agreements. See the NOTICE file distributed with
9+
* this work for additional information regarding copyright
10+
* ownership. Elasticsearch B.V. licenses this file to you under
11+
* the Apache License, Version 2.0 (the "License"); you may
12+
* not use this file except in compliance with the License.
13+
* You may obtain a copy of the License at
14+
*
15+
* http://www.apache.org/licenses/LICENSE-2.0
16+
*
17+
* Unless required by applicable law or agreed to in writing,
18+
* software distributed under the License is distributed on an
19+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
20+
* KIND, either express or implied. See the License for the
21+
* specific language governing permissions and limitations
22+
* under the License.
23+
* #L%
24+
*/
25+
package co.elastic.logging.logback;
26+
27+
class LegacyEcsEncoderTest extends EcsEncoderTest {
28+
29+
}

pom.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
<module>jboss-logmanager-ecs-formatter</module>
1616
<module>log4j2-legacy-tests</module>
1717
<module>log4j-legacy-tests</module>
18+
<module>logback-legacy-tests</module>
1819
</modules>
1920
<packaging>pom</packaging>
2021
<inceptionYear>2019</inceptionYear>

0 commit comments

Comments
 (0)