Skip to content

Commit 30450c4

Browse files
artembilangaryrussell
authored andcommitted
INT-4376: Upgage to Log4J 2 (#2321)
* INT-4376: Upgage to Log4J 2 JIRA: https://jira.spring.io/browse/INT-4376 * Deprecate Log4J 1.x components in favor of newly added a `Log4j2LevelAdjuster` JUnit `@Rule` * Update all the logging configuration to Log4J 2 * Polishing after testing
1 parent 422f651 commit 30450c4

File tree

97 files changed

+981
-539
lines changed

Some content is hidden

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

97 files changed

+981
-539
lines changed

build.gradle

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ subprojects { subproject ->
118118
junitVersion = '4.12'
119119
jythonVersion = '2.5.3'
120120
kryoShadedVersion = '3.0.3'
121-
log4jVersion = '1.2.17'
121+
log4jVersion = '2.10.0'
122122
mockitoVersion = '2.11.0'
123123
mysqlVersion = '6.0.6'
124124
pahoMqttClientVersion = '1.2.0'
@@ -127,7 +127,6 @@ subprojects { subproject ->
127127
reactorVersion = '3.1.2.RELEASE'
128128
romeToolsVersion = '1.8.0'
129129
servletApiVersion = '4.0.0'
130-
slf4jVersion = "1.7.25"
131130
smackVersion = '4.2.2'
132131
springAmqpVersion = project.hasProperty('springAmqpVersion') ? project.springAmqpVersion : '2.0.1.RELEASE'
133132
springDataJpaVersion = '2.0.2.RELEASE'
@@ -160,7 +159,8 @@ subprojects { subproject ->
160159
testCompile project(":spring-integration-test-support")
161160
}
162161

163-
testCompile "org.slf4j:slf4j-log4j12:$slf4jVersion"
162+
testRuntime "org.apache.logging.log4j:log4j-slf4j-impl:$log4jVersion"
163+
testRuntime "org.apache.logging.log4j:log4j-jcl:$log4jVersion"
164164
}
165165

166166
// enable all compiler warnings; individual projects may customize further
@@ -275,7 +275,8 @@ project('spring-integration-test-support') {
275275
compile "org.springframework:spring-context:$springVersion"
276276
compile "org.springframework:spring-messaging:$springVersion"
277277
compile "org.springframework:spring-test:$springVersion"
278-
compile ("log4j:log4j:$log4jVersion", optional)
278+
compile ("org.apache.logging.log4j:log4j-core:$log4jVersion" , optional)
279+
compile ('log4j:log4j:1.2.17', optional)
279280
}
280281
}
281282

spring-integration-amqp/src/test/java/org/springframework/integration/amqp/outbound/AsyncAmqpGatewayTests.java

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2016-2017 the original author or authors.
2+
* Copyright 2016-2018 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -35,7 +35,6 @@
3535
import java.util.concurrent.TimeUnit;
3636

3737
import org.apache.commons.logging.Log;
38-
import org.apache.log4j.Level;
3938
import org.junit.AfterClass;
4039
import org.junit.ClassRule;
4140
import org.junit.Rule;
@@ -59,7 +58,7 @@
5958
import org.springframework.integration.channel.DirectChannel;
6059
import org.springframework.integration.channel.QueueChannel;
6160
import org.springframework.integration.support.MessageBuilder;
62-
import org.springframework.integration.test.rule.Log4jLevelAdjuster;
61+
import org.springframework.integration.test.rule.Log4j2LevelAdjuster;
6362
import org.springframework.messaging.Message;
6463
import org.springframework.messaging.MessagingException;
6564
import org.springframework.messaging.support.ErrorMessage;
@@ -78,8 +77,10 @@ public class AsyncAmqpGatewayTests {
7877
public static BrokerRunning brokerRunning = BrokerRunning.isRunningWithEmptyQueues("asyncQ1", "asyncRQ1");
7978

8079
@Rule
81-
public Log4jLevelAdjuster adjuster = new Log4jLevelAdjuster(Level.TRACE, "org.springframework.integration",
82-
"org.springframework.amqp");
80+
public Log4j2LevelAdjuster adjuster =
81+
Log4j2LevelAdjuster.trace()
82+
.categories("org.springframework.integration",
83+
"org.springframework.amqp");
8384

8485
@AfterClass
8586
public static void tearDown() {

spring-integration-amqp/src/test/resources/log4j.properties

Lines changed: 0 additions & 10 deletions
This file was deleted.
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<Configuration status="WARN">
3+
<Appenders>
4+
<Console name="STDOUT" target="SYSTEM_OUT">
5+
<PatternLayout pattern="%d %p [%t] [%c] - %m%n" />
6+
</Console>
7+
</Appenders>
8+
<Loggers>
9+
<Logger name="test" level="debug"/>
10+
<Logger name="org.springframework" level="warn"/>
11+
<Logger name="org.springframework.amqp" level="warn"/>
12+
<Logger name="org.springframework.integration.amqp" level="warn"/>
13+
<Root level="warn">
14+
<AppenderRef ref="STDOUT" />
15+
</Root>
16+
</Loggers>
17+
</Configuration>

spring-integration-core/src/test/java/org/springframework/integration/aggregator/scenarios/AggregatorWithCustomReleaseStrategyTests.java

Lines changed: 6 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2016 the original author or authors.
2+
* Copyright 2002-2018 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -25,60 +25,27 @@
2525
import java.util.concurrent.TimeUnit;
2626

2727
import org.junit.AfterClass;
28-
import org.junit.Assume;
29-
import org.junit.Rule;
28+
import org.junit.ClassRule;
3029
import org.junit.Test;
31-
import org.junit.rules.TestWatcher;
32-
import org.junit.runner.Description;
33-
import org.junit.runners.model.Statement;
3430

3531
import org.springframework.context.support.AbstractApplicationContext;
3632
import org.springframework.context.support.ClassPathXmlApplicationContext;
3733
import org.springframework.integration.channel.QueueChannel;
3834
import org.springframework.integration.support.MessageBuilder;
35+
import org.springframework.integration.test.support.LongRunningIntegrationTest;
3936
import org.springframework.messaging.Message;
4037
import org.springframework.messaging.MessageChannel;
4138

4239
/**
4340
* @author Oleg Zhurakousky
4441
* @author Gary Russell
42+
* @author Artem Bilan
4543
*
4644
*/
4745
public class AggregatorWithCustomReleaseStrategyTests {
4846

49-
@Rule
50-
public TestWatcher longTests = new TestWatcher() {
51-
52-
private static final String RUN_LONG_PROP = "RUN_LONG_INTEGRATION_TESTS";
53-
54-
private boolean shouldRun;
55-
56-
{
57-
for (String value: new String[]{System.getenv(RUN_LONG_PROP), System.getProperty(RUN_LONG_PROP)}) {
58-
if ("true".equalsIgnoreCase(value)) {
59-
this.shouldRun = true;
60-
break;
61-
}
62-
}
63-
}
64-
65-
@Override
66-
public Statement apply(Statement base, Description description) {
67-
if (!this.shouldRun) {
68-
return new Statement() {
69-
70-
@Override
71-
public void evaluate() throws Throwable {
72-
Assume.assumeTrue(false);
73-
}
74-
};
75-
}
76-
else {
77-
return super.apply(base, description);
78-
}
79-
}
80-
81-
};
47+
@ClassRule
48+
public static LongRunningIntegrationTest longTests = new LongRunningIntegrationTest();
8249

8350
private static ExecutorService executor = Executors.newCachedThreadPool();
8451

spring-integration-core/src/test/java/org/springframework/integration/config/xml/LoggingChannelAdapterParserTests.java

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2013 the original author or authors.
2+
* Copyright 2002-2018 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -40,6 +40,7 @@
4040
* @author Mark Fisher
4141
* @author Artem Bilan
4242
* @author Gary Russell
43+
*
4344
* @since 2.1
4445
*/
4546
@ContextConfiguration
@@ -56,7 +57,8 @@ public class LoggingChannelAdapterParserTests {
5657
@Test
5758
public void verifyConfig() {
5859
LoggingHandler loggingHandler = TestUtils.getPropertyValue(loggerConsumer, "handler", LoggingHandler.class);
59-
assertEquals("org.springframework.integration.test.logger", TestUtils.getPropertyValue(loggingHandler, "messageLogger.name"));
60+
assertEquals("org.springframework.integration.test.logger",
61+
TestUtils.getPropertyValue(loggingHandler, "messageLogger.logger.name"));
6062
assertEquals(1, TestUtils.getPropertyValue(loggingHandler, "order"));
6163
assertEquals("WARN", TestUtils.getPropertyValue(loggingHandler, "level").toString());
6264
assertEquals("#root", TestUtils.getPropertyValue(loggingHandler, "expression.expression"));
@@ -65,7 +67,8 @@ public void verifyConfig() {
6567
@Test
6668
public void verifyExpressionAndOtherDefaultConfig() {
6769
LoggingHandler loggingHandler = TestUtils.getPropertyValue(loggerWithExpression, "handler", LoggingHandler.class);
68-
assertEquals("org.springframework.integration.handler.LoggingHandler", TestUtils.getPropertyValue(loggingHandler, "messageLogger.name"));
70+
assertEquals("org.springframework.integration.handler.LoggingHandler",
71+
TestUtils.getPropertyValue(loggingHandler, "messageLogger.logger.name"));
6972
assertEquals(Ordered.LOWEST_PRECEDENCE, TestUtils.getPropertyValue(loggingHandler, "order"));
7073
assertEquals("INFO", TestUtils.getPropertyValue(loggingHandler, "level").toString());
7174
assertEquals("payload.foo", TestUtils.getPropertyValue(loggingHandler, "expression.expression"));

spring-integration-core/src/test/java/org/springframework/integration/endpoint/PollerAdviceTests.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2014-2017 the original author or authors.
2+
* Copyright 2014-2018 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -42,7 +42,6 @@
4242
import org.aopalliance.aop.Advice;
4343
import org.aopalliance.intercept.Joinpoint;
4444
import org.aopalliance.intercept.MethodInterceptor;
45-
import org.apache.log4j.Level;
4645
import org.junit.Rule;
4746
import org.junit.Test;
4847
import org.junit.runner.RunWith;
@@ -67,7 +66,7 @@
6766
import org.springframework.integration.core.MessageSource;
6867
import org.springframework.integration.scheduling.PollSkipAdvice;
6968
import org.springframework.integration.scheduling.SimplePollSkipStrategy;
70-
import org.springframework.integration.test.rule.Log4jLevelAdjuster;
69+
import org.springframework.integration.test.rule.Log4j2LevelAdjuster;
7170
import org.springframework.integration.test.util.OnlyOnceTrigger;
7271
import org.springframework.integration.test.util.TestUtils;
7372
import org.springframework.integration.util.CompoundTrigger;
@@ -85,6 +84,8 @@
8584

8685
/**
8786
* @author Gary Russell
87+
* @author Artem Bilan
88+
*
8889
* @since 4.1
8990
*
9091
*/
@@ -94,7 +95,7 @@
9495
public class PollerAdviceTests {
9596

9697
@Rule
97-
public Log4jLevelAdjuster adjuster = new Log4jLevelAdjuster(Level.TRACE, "org.springframework.integration");
98+
public Log4j2LevelAdjuster adjuster = Log4j2LevelAdjuster.trace();
9899

99100
@Autowired
100101
private MessageChannel control;

0 commit comments

Comments
 (0)