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
This commit is contained in:
@@ -43,6 +43,7 @@ import ch.qos.logback.classic.util.ContextInitializer;
|
||||
*
|
||||
* @author Phillip Webb
|
||||
* @author Dave Syer
|
||||
* @author Andy Wilkinson
|
||||
*/
|
||||
public class LogbackLoggingSystem extends AbstractLoggingSystem {
|
||||
|
||||
@@ -67,6 +68,11 @@ public class LogbackLoggingSystem extends AbstractLoggingSystem {
|
||||
@Override
|
||||
public void beforeInitialize() {
|
||||
super.beforeInitialize();
|
||||
configureJdkLoggingBridgeHandler();
|
||||
configureJBossLoggingToUseSlf4j();
|
||||
}
|
||||
|
||||
private void configureJdkLoggingBridgeHandler() {
|
||||
try {
|
||||
if (ClassUtils.isPresent("org.slf4j.bridge.SLF4JBridgeHandler",
|
||||
getClassLoader())) {
|
||||
@@ -85,6 +91,10 @@ public class LogbackLoggingSystem extends AbstractLoggingSystem {
|
||||
}
|
||||
}
|
||||
|
||||
private void configureJBossLoggingToUseSlf4j() {
|
||||
System.setProperty("org.jboss.logging.provider", "slf4j");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void initialize(String configLocation) {
|
||||
Assert.notNull(configLocation, "ConfigLocation must not be null");
|
||||
|
||||
@@ -34,6 +34,7 @@ import ch.qos.logback.classic.Logger;
|
||||
import ch.qos.logback.classic.LoggerContext;
|
||||
|
||||
import static org.hamcrest.Matchers.equalTo;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertThat;
|
||||
@@ -43,6 +44,7 @@ import static org.junit.Assert.assertTrue;
|
||||
* Tests for {@link LogbackLoggingSystem}.
|
||||
*
|
||||
* @author Dave Syer
|
||||
* @author Andy Wilkinson
|
||||
*/
|
||||
public class LogbackLoggingSystemTests {
|
||||
|
||||
@@ -119,4 +121,10 @@ public class LogbackLoggingSystemTests {
|
||||
equalTo(1));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void jbossLoggingIsConfiguredToUseSlf4j() {
|
||||
this.loggingSystem.beforeInitialize();
|
||||
assertEquals("slf4j", System.getProperty("org.jboss.logging.provider"));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user