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
This commit is contained in:
Artem Bilan
2018-01-11 10:59:55 -05:00
committed by Gary Russell
parent 422f651113
commit 30450c48be
97 changed files with 981 additions and 539 deletions

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2015-2017 the original author or authors.
* Copyright 2015-2018 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -28,6 +28,7 @@ import static org.junit.Assert.fail;
import org.apache.activemq.broker.BrokerService;
import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.Rule;
import org.junit.Test;
import org.springframework.context.ApplicationEvent;
@@ -51,7 +52,7 @@ import org.springframework.integration.stomp.event.StompSessionConnectedEvent;
import org.springframework.integration.stomp.inbound.StompInboundChannelAdapter;
import org.springframework.integration.stomp.outbound.StompMessageHandler;
import org.springframework.integration.support.converter.PassThruMessageConverter;
import org.springframework.integration.test.support.LogAdjustingTestSupport;
import org.springframework.integration.test.rule.Log4j2LevelAdjuster;
import org.springframework.messaging.Message;
import org.springframework.messaging.MessageChannel;
import org.springframework.messaging.MessageDeliveryException;
@@ -66,19 +67,23 @@ import org.springframework.util.SocketUtils;
/**
* @author Artem Bilan
* @author Gary Russell
*
* @since 4.2
*/
public class StompServerIntegrationTests extends LogAdjustingTestSupport {
public class StompServerIntegrationTests {
private static BrokerService activeMQBroker;
private static ReactorNettyTcpStompClient stompClient;
public StompServerIntegrationTests() {
super("org.springframework", "org.springframework.integration.stomp",
"org.apache.activemq.broker", "reactor.ipc", "io.netty");
}
@Rule
public Log4j2LevelAdjuster adjuster =
Log4j2LevelAdjuster.trace()
.categories("org.springframework",
"org.springframework.integration.stomp",
"org.apache.activemq.broker",
"reactor.ipc",
"io.netty");
@BeforeClass
public static void setup() throws Exception {

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2015-2017 the original author or authors.
* Copyright 2015-2018 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -27,6 +27,7 @@ import static org.junit.Assert.assertTrue;
import java.util.Collections;
import java.util.Map;
import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
@@ -50,7 +51,7 @@ import org.springframework.integration.stomp.event.StompConnectionFailedEvent;
import org.springframework.integration.stomp.event.StompIntegrationEvent;
import org.springframework.integration.stomp.event.StompReceiptEvent;
import org.springframework.integration.stomp.event.StompSessionConnectedEvent;
import org.springframework.integration.test.support.LogAdjustingTestSupport;
import org.springframework.integration.test.rule.Log4j2LevelAdjuster;
import org.springframework.integration.websocket.TomcatWebSocketTestServer;
import org.springframework.messaging.Message;
import org.springframework.messaging.MessageHandlingException;
@@ -90,12 +91,18 @@ import org.springframework.web.socket.sockjs.client.WebSocketTransport;
/**
* @author Artem Bilan
*
* @since 4.2
*/
@ContextConfiguration(classes = StompInboundChannelAdapterWebSocketIntegrationTests.ContextConfiguration.class)
@RunWith(SpringJUnit4ClassRunner.class)
@DirtiesContext
public class StompInboundChannelAdapterWebSocketIntegrationTests extends LogAdjustingTestSupport {
public class StompInboundChannelAdapterWebSocketIntegrationTests {
@Rule
public Log4j2LevelAdjuster adjuster =
Log4j2LevelAdjuster.trace()
.categories("org.springframework", "org.springframework.integration.stomp");
@Value("#{server.serverContext}")
private ConfigurableApplicationContext serverContext;
@@ -115,9 +122,6 @@ public class StompInboundChannelAdapterWebSocketIntegrationTests extends LogAdju
@Autowired
private StompInboundChannelAdapter stompInboundChannelAdapter;
public StompInboundChannelAdapterWebSocketIntegrationTests() {
super("org.springframework", "org.springframework.integration.stomp");
}
@Test
public void testWebSocketStompClient() throws Exception {
@@ -274,7 +278,7 @@ public class StompInboundChannelAdapterWebSocketIntegrationTests extends LogAdju
handshakeHeaders.setOrigin("http://foo.com");
webSocketStompSessionManager.setHandshakeHeaders(handshakeHeaders);
StompHeaders stompHeaders = new StompHeaders();
stompHeaders.setHeartbeat(new long[] {10000, 10000});
stompHeaders.setHeartbeat(new long[] { 10000, 10000 });
webSocketStompSessionManager.setConnectHeaders(stompHeaders);
return webSocketStompSessionManager;
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2015-2017 the original author or authors.
* Copyright 2015-2018 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -33,6 +33,7 @@ import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicBoolean;
import org.junit.ClassRule;
import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
@@ -55,7 +56,7 @@ import org.springframework.integration.stomp.event.StompExceptionEvent;
import org.springframework.integration.stomp.event.StompIntegrationEvent;
import org.springframework.integration.stomp.event.StompReceiptEvent;
import org.springframework.integration.stomp.event.StompSessionConnectedEvent;
import org.springframework.integration.test.support.LogAdjustingTestSupport;
import org.springframework.integration.test.rule.Log4j2LevelAdjuster;
import org.springframework.integration.test.support.LongRunningIntegrationTest;
import org.springframework.integration.websocket.TomcatWebSocketTestServer;
import org.springframework.messaging.Message;
@@ -97,11 +98,16 @@ import org.springframework.web.socket.sockjs.client.WebSocketTransport;
@ContextConfiguration(classes = StompMessageHandlerWebSocketIntegrationTests.ContextConfiguration.class)
@RunWith(SpringJUnit4ClassRunner.class)
@DirtiesContext
public class StompMessageHandlerWebSocketIntegrationTests extends LogAdjustingTestSupport {
public class StompMessageHandlerWebSocketIntegrationTests {
@ClassRule
public static LongRunningIntegrationTest longTests = new LongRunningIntegrationTest();
@Rule
public Log4j2LevelAdjuster adjuster =
Log4j2LevelAdjuster.trace()
.categories("org.springframework", "org.springframework.integration.stomp");
@Value("#{server.serverContext}")
private ApplicationContext serverContext;
@@ -113,10 +119,6 @@ public class StompMessageHandlerWebSocketIntegrationTests extends LogAdjustingTe
@Qualifier("stompEvents")
private PollableChannel stompEvents;
public StompMessageHandlerWebSocketIntegrationTests() {
super("org.springframework", "org.springframework.integration.stomp");
}
@Test
public void testStompMessageHandler() throws InterruptedException {
StompHeaderAccessor headers = StompHeaderAccessor.create(StompCommand.SEND);
@@ -225,10 +227,11 @@ public class StompMessageHandlerWebSocketIntegrationTests extends LogAdjustingTe
// WebSocket Server part
@Target({ElementType.TYPE})
@Target({ ElementType.TYPE })
@Retention(RetentionPolicy.RUNTIME)
@Controller
private @interface IntegrationTestController {
}
@IntegrationTestController

View File

@@ -1,9 +0,0 @@
log4j.rootCategory=WARN, stdout
log4j.appender.stdout=org.apache.log4j.ConsoleAppender
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
log4j.appender.stdout.layout.ConversionPattern=%d{HH:mm:ss.SSS} %-5p [%t][%c] %m%n
#log4j.category.org.springframework=DEBUG
#log4j.category.org.springframework.integration=DEBUG
log4j.category.org.springframework.integration.stomp=WARN

View File

@@ -0,0 +1,16 @@
<?xml version="1.0" encoding="UTF-8"?>
<Configuration status="WARN">
<Appenders>
<Console name="STDOUT" target="SYSTEM_OUT">
<PatternLayout pattern="%d %p [%t] [%c] - %m%n" />
</Console>
</Appenders>
<Loggers>
<Logger name="org.springframework" level="warn"/>
<Logger name="org.springframework.integration" level="warn"/>
<Logger name="org.springframework.integration.stomp" level="warn"/>
<Root level="warn">
<AppenderRef ref="STDOUT" />
</Root>
</Loggers>
</Configuration>