Skip to content

Commit 59ebc3b

Browse files
committed
When Logback is the logging system, ensure that JBoss logging uses it
Previously, if Logback was being used as Boot's logging system, but Log4J was also on the classpath before SLF4J and Logback, JBoss Logging would use Log4J for its logging. This lead to warning messages being produced as Log4J was not configured: log4j:WARN No appenders could be found for logger (org.jboss.logging). log4j:WARN Please initialize the log4j system properly. This commit updates LogbackLoggingSystem to set the org.jboss.logging.provider to "slf4j". This ensure that JBoss Logging will use SLF4J and Logback as intended even when Log4J is also on the classpath. Closes gh-1928
1 parent 9059c75 commit 59ebc3b

File tree

2 files changed

+18
-0
lines changed

2 files changed

+18
-0
lines changed

spring-boot/src/main/java/org/springframework/boot/logging/logback/LogbackLoggingSystem.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@
4343
*
4444
* @author Phillip Webb
4545
* @author Dave Syer
46+
* @author Andy Wilkinson
4647
*/
4748
public class LogbackLoggingSystem extends AbstractLoggingSystem {
4849

@@ -67,6 +68,11 @@ public LogbackLoggingSystem(ClassLoader classLoader) {
6768
@Override
6869
public void beforeInitialize() {
6970
super.beforeInitialize();
71+
configureJdkLoggingBridgeHandler();
72+
configureJBossLoggingToUseSlf4j();
73+
}
74+
75+
private void configureJdkLoggingBridgeHandler() {
7076
try {
7177
if (ClassUtils.isPresent("org.slf4j.bridge.SLF4JBridgeHandler",
7278
getClassLoader())) {
@@ -85,6 +91,10 @@ public void beforeInitialize() {
8591
}
8692
}
8793

94+
private void configureJBossLoggingToUseSlf4j() {
95+
System.setProperty("org.jboss.logging.provider", "slf4j");
96+
}
97+
8898
@Override
8999
public void initialize(String configLocation) {
90100
Assert.notNull(configLocation, "ConfigLocation must not be null");

spring-boot/src/test/java/org/springframework/boot/logging/logback/LogbackLoggingSystemTests.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
import ch.qos.logback.classic.LoggerContext;
3535

3636
import static org.hamcrest.Matchers.equalTo;
37+
import static org.junit.Assert.assertEquals;
3738
import static org.junit.Assert.assertFalse;
3839
import static org.junit.Assert.assertNotNull;
3940
import static org.junit.Assert.assertThat;
@@ -43,6 +44,7 @@
4344
* Tests for {@link LogbackLoggingSystem}.
4445
*
4546
* @author Dave Syer
47+
* @author Andy Wilkinson
4648
*/
4749
public class LogbackLoggingSystemTests {
4850

@@ -119,4 +121,10 @@ public void setLevel() throws Exception {
119121
equalTo(1));
120122
}
121123

124+
@Test
125+
public void jbossLoggingIsConfiguredToUseSlf4j() {
126+
this.loggingSystem.beforeInitialize();
127+
assertEquals("slf4j", System.getProperty("org.jboss.logging.provider"));
128+
}
129+
122130
}

0 commit comments

Comments
 (0)