Skip to content

Commit a0d9faf

Browse files
Migrate Log4j test dependencies from version 1.2.17 to 2.17.1 (#2947)
Note: The SDK only depends on log4j as a test-time dependency. Test dependencies aren't transitive and are only present for test class paths. Therefore, this change will have no effect on end users that depend on the SDK (and the SDK has not been exposing users to any of the recent log4j-related CVEs). Modifications: 1. Migrate Log4j from version `1.2.17` to `2.17.1`. This replaces Maven artifact `log4j`/`log4j` with `org.apache.logging.log4j`/`log4j-api` and `org.apache.logging.log4j`/`log4j-core`. 2. Migrate our logging bridge/binding from `org.slf4j`/`slf4j-log4j12` to `org.apache.logging.log4j`/`log4j-slf4j-impl`. 3. Replace `log4j.properties` files with `log4j2.properties` files (using the new Log4j2 property syntax). 4. Update `LogCaptor` (used for unit testing logging events) to Log4j2. 5. Remove a few explicit and unnecessary calls to Log4j1's `BasicConfigurator.configure()`. Helpful resources: 1. https://logging.apache.org/log4j/2.x/manual/migration.html 2. https://logging.apache.org/log4j/2.x/manual/configuration.html#Properties 3. https://logging.apache.org/log4j/2.x/log4j-slf4j-impl/
1 parent 313edb9 commit a0d9faf

File tree

88 files changed

+1133
-1071
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

88 files changed

+1133
-1071
lines changed

bom-internal/pom.xml

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -253,15 +253,24 @@
253253
<scope>test</scope>
254254
</dependency>
255255
<dependency>
256-
<groupId>log4j</groupId>
257-
<artifactId>log4j</artifactId>
256+
<!-- Log4j2 API -->
257+
<groupId>org.apache.logging.log4j</groupId>
258+
<artifactId>log4j-api</artifactId>
258259
<version>${log4j.version}</version>
259260
<scope>test</scope>
260261
</dependency>
261262
<dependency>
262-
<groupId>org.slf4j</groupId>
263-
<artifactId>slf4j-log4j12</artifactId>
264-
<version>${slf4j.version}</version>
263+
<!-- Log4j2 Core -->
264+
<groupId>org.apache.logging.log4j</groupId>
265+
<artifactId>log4j-core</artifactId>
266+
<version>${log4j.version}</version>
267+
<scope>test</scope>
268+
</dependency>
269+
<dependency>
270+
<!-- Bind SLF4J to Log4j2 -->
271+
<groupId>org.apache.logging.log4j</groupId>
272+
<artifactId>log4j-slf4j-impl</artifactId>
273+
<version>${log4j.version}</version>
265274
<scope>test</scope>
266275
</dependency>
267276
<dependency>

core/auth-crt/pom.xml

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -84,13 +84,18 @@
8484
<scope>test</scope>
8585
</dependency>
8686
<dependency>
87-
<groupId>log4j</groupId>
88-
<artifactId>log4j</artifactId>
87+
<groupId>org.apache.logging.log4j</groupId>
88+
<artifactId>log4j-api</artifactId>
8989
<scope>test</scope>
9090
</dependency>
9191
<dependency>
92-
<groupId>org.slf4j</groupId>
93-
<artifactId>slf4j-log4j12</artifactId>
92+
<groupId>org.apache.logging.log4j</groupId>
93+
<artifactId>log4j-core</artifactId>
94+
<scope>test</scope>
95+
</dependency>
96+
<dependency>
97+
<groupId>org.apache.logging.log4j</groupId>
98+
<artifactId>log4j-slf4j-impl</artifactId>
9499
<scope>test</scope>
95100
</dependency>
96101
<dependency>

core/auth/pom.xml

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -88,13 +88,18 @@
8888
<scope>test</scope>
8989
</dependency>
9090
<dependency>
91-
<groupId>log4j</groupId>
92-
<artifactId>log4j</artifactId>
91+
<groupId>org.apache.logging.log4j</groupId>
92+
<artifactId>log4j-api</artifactId>
9393
<scope>test</scope>
9494
</dependency>
9595
<dependency>
96-
<groupId>org.slf4j</groupId>
97-
<artifactId>slf4j-log4j12</artifactId>
96+
<groupId>org.apache.logging.log4j</groupId>
97+
<artifactId>log4j-core</artifactId>
98+
<scope>test</scope>
99+
</dependency>
100+
<dependency>
101+
<groupId>org.apache.logging.log4j</groupId>
102+
<artifactId>log4j-slf4j-impl</artifactId>
98103
<scope>test</scope>
99104
</dependency>
100105
<dependency>

core/auth/src/it/java/software/amazon/awssdk/auth/credentials/InstanceProfileCredentialsProviderIntegrationTest.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,11 @@
2424
import org.junit.Test;
2525
import software.amazon.awssdk.core.SdkSystemSetting;
2626
import software.amazon.awssdk.core.exception.SdkClientException;
27-
import software.amazon.awssdk.testutils.LogCaptor;
2827

2928
/**
3029
* Unit tests for the InstanceProfileCredentialsProvider.
3130
*/
32-
public class InstanceProfileCredentialsProviderIntegrationTest extends LogCaptor.LogCaptorTestBase {
31+
public class InstanceProfileCredentialsProviderIntegrationTest {
3332

3433
private EC2MetadataServiceMock mockServer;
3534

core/auth/src/test/resources/log4j.properties

Lines changed: 0 additions & 37 deletions
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,24 @@
1-
#
2-
# Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
3-
#
4-
# Licensed under the Apache License, Version 2.0 (the "License").
5-
# You may not use this file except in compliance with the License.
6-
# A copy of the License is located at
7-
#
8-
# http://aws.amazon.com/apache2.0
9-
#
10-
# or in the "license" file accompanying this file. This file is distributed
11-
# on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
12-
# express or implied. See the License for the specific language governing
13-
# permissions and limitations under the License.
14-
#
15-
16-
log4j.rootLogger=WARN, A1
17-
log4j.appender.A1=org.apache.log4j.ConsoleAppender
18-
log4j.appender.A1.layout=org.apache.log4j.PatternLayout
19-
20-
# Print the date in ISO 8601 format
21-
log4j.appender.A1.layout.ConversionPattern=%d [%t] %-5p %c - %m%n
22-
23-
24-
1+
#
2+
# Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
3+
#
4+
# Licensed under the Apache License, Version 2.0 (the "License").
5+
# You may not use this file except in compliance with the License.
6+
# A copy of the License is located at
7+
#
8+
# http://aws.amazon.com/apache2.0
9+
#
10+
# or in the "license" file accompanying this file. This file is distributed
11+
# on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
12+
# express or implied. See the License for the specific language governing
13+
# permissions and limitations under the License.
14+
#
15+
16+
status = warn
17+
18+
appender.console.type = Console
19+
appender.console.name = ConsoleAppender
20+
appender.console.layout.type = PatternLayout
21+
appender.console.layout.pattern = %d{HH:mm:ss.SSS} [%t] %-5level %logger{36} - %msg%n%throwable
22+
23+
rootLogger.level = info
24+
rootLogger.appenderRef.stdout.ref = ConsoleAppender

core/aws-core/pom.xml

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -95,18 +95,23 @@
9595
<scope>test</scope>
9696
</dependency>
9797
<dependency>
98-
<groupId>log4j</groupId>
99-
<artifactId>log4j</artifactId>
98+
<groupId>org.apache.logging.log4j</groupId>
99+
<artifactId>log4j-api</artifactId>
100100
<scope>test</scope>
101101
</dependency>
102102
<dependency>
103-
<groupId>com.github.tomakehurst</groupId>
104-
<artifactId>wiremock</artifactId>
103+
<groupId>org.apache.logging.log4j</groupId>
104+
<artifactId>log4j-core</artifactId>
105105
<scope>test</scope>
106106
</dependency>
107107
<dependency>
108-
<groupId>org.slf4j</groupId>
109-
<artifactId>slf4j-log4j12</artifactId>
108+
<groupId>org.apache.logging.log4j</groupId>
109+
<artifactId>log4j-slf4j-impl</artifactId>
110+
<scope>test</scope>
111+
</dependency>
112+
<dependency>
113+
<groupId>com.github.tomakehurst</groupId>
114+
<artifactId>wiremock</artifactId>
110115
<scope>test</scope>
111116
</dependency>
112117
<dependency>

core/aws-core/src/test/resources/log4j.properties

Lines changed: 0 additions & 35 deletions
This file was deleted.

release-scripts/src/main/resources/log4j.properties renamed to core/aws-core/src/test/resources/log4j2.properties

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,12 @@
1313
# permissions and limitations under the License.
1414
#
1515

16-
log4j.rootLogger=INFO, A1
17-
log4j.appender.A1=org.apache.log4j.ConsoleAppender
18-
log4j.appender.A1.layout=org.apache.log4j.PatternLayout
16+
status = warn
1917

20-
# Print the date in ISO 8601 format
21-
log4j.appender.A1.layout.ConversionPattern=%d [%t] %-5p %c - %m%n
18+
appender.console.type = Console
19+
appender.console.name = ConsoleAppender
20+
appender.console.layout.type = PatternLayout
21+
appender.console.layout.pattern = %d{HH:mm:ss.SSS} [%t] %-5level %logger{36} - %msg%n%throwable
22+
23+
rootLogger.level = info
24+
rootLogger.appenderRef.stdout.ref = ConsoleAppender

core/metrics-spi/pom.xml

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -58,13 +58,18 @@
5858
<scope>test</scope>
5959
</dependency>
6060
<dependency>
61-
<groupId>log4j</groupId>
62-
<artifactId>log4j</artifactId>
61+
<groupId>org.apache.logging.log4j</groupId>
62+
<artifactId>log4j-api</artifactId>
6363
<scope>test</scope>
6464
</dependency>
6565
<dependency>
66-
<groupId>org.slf4j</groupId>
67-
<artifactId>slf4j-log4j12</artifactId>
66+
<groupId>org.apache.logging.log4j</groupId>
67+
<artifactId>log4j-core</artifactId>
68+
<scope>test</scope>
69+
</dependency>
70+
<dependency>
71+
<groupId>org.apache.logging.log4j</groupId>
72+
<artifactId>log4j-slf4j-impl</artifactId>
6873
<scope>test</scope>
6974
</dependency>
7075
</dependencies>

core/metrics-spi/src/test/java/software/amazon/awssdk/metrics/LoggingMetricPublisherTest.java

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,8 @@
1515

1616
package software.amazon.awssdk.metrics;
1717

18-
import static org.apache.log4j.Level.ALL;
19-
import static org.apache.log4j.Level.DEBUG;
20-
import static org.apache.log4j.Level.INFO;
18+
import static org.apache.logging.log4j.Level.DEBUG;
19+
import static org.apache.logging.log4j.Level.INFO;
2120
import static org.assertj.core.api.Assertions.assertThat;
2221

2322
import java.util.Arrays;
@@ -26,7 +25,7 @@
2625
import java.util.Map;
2726
import java.util.stream.Collectors;
2827
import java.util.stream.Stream;
29-
import org.apache.log4j.spi.LoggingEvent;
28+
import org.apache.logging.log4j.core.LogEvent;
3029
import org.junit.jupiter.api.Test;
3130
import org.slf4j.event.Level;
3231
import software.amazon.awssdk.metrics.LoggingMetricPublisher.Format;
@@ -46,11 +45,10 @@ void testDefaultConfiguration() {
4645
MetricCollection foo = metrics("foo", bar, qux);
4746

4847
LoggingMetricPublisher publisher = LoggingMetricPublisher.create();
49-
publisher.publish(foo);
5048

51-
try (LogCaptor logCaptor = new LogCaptor.DefaultLogCaptor(ALL)) {
49+
try (LogCaptor logCaptor = LogCaptor.create()) {
5250
publisher.publish(foo);
53-
List<LoggingEvent> events = logCaptor.loggedEvents();
51+
List<LogEvent> events = logCaptor.loggedEvents();
5452
assertLogged(events, INFO, "Metrics published: %s", foo);
5553
assertThat(events).isEmpty();
5654
}
@@ -65,11 +63,10 @@ void testPrettyFormat() {
6563
String guid = Integer.toHexString(foo.hashCode());
6664

6765
LoggingMetricPublisher publisher = LoggingMetricPublisher.create(Level.DEBUG, Format.PRETTY);
68-
publisher.publish(foo);
6966

70-
try (LogCaptor logCaptor = new LogCaptor.DefaultLogCaptor(ALL)) {
67+
try (LogCaptor logCaptor = LogCaptor.create()) {
7168
publisher.publish(foo);
72-
List<LoggingEvent> events = logCaptor.loggedEvents();
69+
List<LogEvent> events = logCaptor.loggedEvents();
7370
assertLogged(events, DEBUG, "[%s] foo", guid);
7471
assertLogged(events, DEBUG, "[%s] ┌──────────────────────────────┐", guid);
7572
assertLogged(events, DEBUG, "[%s] │ LoggingMetricPublisherTest=1 │", guid);
@@ -107,9 +104,11 @@ private static MetricCollection metrics(String name, MetricCollection... childre
107104
return new DefaultMetricCollection(name, recordMap, Arrays.asList(children));
108105
}
109106

110-
private static void assertLogged(List<LoggingEvent> events, org.apache.log4j.Level level, String message, Object... args) {
111-
LoggingEvent event = events.remove(0);
107+
private static void assertLogged(List<LogEvent> events, org.apache.logging.log4j.Level level, String message, Object... args) {
108+
assertThat(events).withFailMessage("Expecting events to not be empty").isNotEmpty();
109+
LogEvent event = events.remove(0);
110+
String msg = event.getMessage().getFormattedMessage();
111+
assertThat(msg).isEqualTo(String.format(message, args));
112112
assertThat(event.getLevel()).isEqualTo(level);
113-
assertThat(event.getMessage()).isEqualTo(String.format(message, args));
114113
}
115114
}

core/metrics-spi/src/test/resources/log4j.properties

Lines changed: 0 additions & 33 deletions
This file was deleted.

0 commit comments

Comments
 (0)