diff --git a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/logging/logback/LogbackLoggingSystemProperties.java b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/logging/logback/LogbackLoggingSystemProperties.java index 74adcd51da8e..9aa2ba5620c5 100644 --- a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/logging/logback/LogbackLoggingSystemProperties.java +++ b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/logging/logback/LogbackLoggingSystemProperties.java @@ -20,6 +20,7 @@ import java.util.function.BiConsumer; import ch.qos.logback.core.util.FileSize; +import org.flywaydb.core.internal.util.ClassUtils; import org.springframework.boot.logging.LogFile; import org.springframework.boot.logging.LoggingSystemProperties; @@ -37,6 +38,9 @@ */ public class LogbackLoggingSystemProperties extends LoggingSystemProperties { + private static final boolean JBOSS_LOGGING_PRESENT = ClassUtils.isPresent("org.jboss.logging.Logger", + LogbackLoggingSystemProperties.class.getClassLoader()); + /** * The name of the System property that contains the rolled-over log file name * pattern. @@ -85,6 +89,17 @@ protected Charset getDefaultCharset() { @Override protected void apply(LogFile logFile, PropertyResolver resolver) { super.apply(logFile, resolver); + applyJBossLoggingProperties(); + applyRollingPolicyProperties(resolver); + } + + private void applyJBossLoggingProperties() { + if (JBOSS_LOGGING_PRESENT) { + setSystemProperty("org.jboss.logging.provider", "slf4j"); + } + } + + private void applyRollingPolicyProperties(PropertyResolver resolver) { applyRollingPolicy(resolver, ROLLINGPOLICY_FILE_NAME_PATTERN, "logging.logback.rollingpolicy.file-name-pattern", "logging.pattern.rolling-file-name"); applyRollingPolicy(resolver, ROLLINGPOLICY_CLEAN_HISTORY_ON_START, diff --git a/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/logging/logback/LogbackLoggingSystemTests.java b/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/logging/logback/LogbackLoggingSystemTests.java index 5871e5885302..cba6f68e7e3a 100644 --- a/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/logging/logback/LogbackLoggingSystemTests.java +++ b/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/logging/logback/LogbackLoggingSystemTests.java @@ -55,6 +55,7 @@ import org.springframework.boot.logging.LoggingInitializationContext; import org.springframework.boot.logging.LoggingSystem; import org.springframework.boot.logging.LoggingSystemProperties; +import org.springframework.boot.testsupport.classpath.ClassPathOverrides; import org.springframework.boot.testsupport.system.CapturedOutput; import org.springframework.boot.testsupport.system.OutputCaptureExtension; import org.springframework.core.convert.ConversionService; @@ -118,6 +119,22 @@ void cleanUp() { ((LoggerContext) LoggerFactory.getILoggerFactory()).stop(); } + @Test + @ClassPathOverrides("org.jboss.logging:jboss-logging:3.5.0.Final") + void jbossLoggingRoutesThroughLog4j2ByDefault() { + org.jboss.logging.Logger jbossLogger = org.jboss.logging.Logger.getLogger(getClass()); + assertThat(jbossLogger.getClass().getName()).isEqualTo("org.jboss.logging.Log4j2Logger"); + } + + @Test + @ClassPathOverrides("org.jboss.logging:jboss-logging:3.5.0.Final") + void jbossLoggingRoutesThroughSlf4jWhenLoggingSystemIsInitialized() { + this.loggingSystem.beforeInitialize(); + initialize(this.initializationContext, null, null); + assertThat(org.jboss.logging.Logger.getLogger(getClass()).getClass().getName()) + .isEqualTo("org.jboss.logging.Slf4jLocationAwareLogger"); + } + @Test void noFile(CapturedOutput output) { this.loggingSystem.beforeInitialize(); @@ -523,6 +540,7 @@ void initializeShouldApplyLogbackSystemPropertiesToTheContext() { ReflectionUtils.doWithFields(LogbackLoggingSystemProperties.class, (field) -> expectedProperties.add((String) field.get(null)), this::isPublicStaticFinal); expectedProperties.removeAll(Arrays.asList("LOG_FILE", "LOG_PATH")); + expectedProperties.add("org.jboss.logging.provider"); assertThat(properties).containsOnlyKeys(expectedProperties); assertThat(properties).containsEntry("CONSOLE_LOG_CHARSET", Charset.defaultCharset().name()); }