diff --git a/spring-geode-project/spring-geode-starters/spring-geode-starter-logging/spring-geode-starter-logging.gradle b/spring-geode-project/spring-geode-starters/spring-geode-starter-logging/spring-geode-starter-logging.gradle index 6b5ca4f0..ddd35307 100644 --- a/spring-geode-project/spring-geode-starters/spring-geode-starter-logging/spring-geode-starter-logging.gradle +++ b/spring-geode-project/spring-geode-starters/spring-geode-starter-logging/spring-geode-starter-logging.gradle @@ -9,6 +9,7 @@ dependencies { api "org.apache.logging.log4j:log4j-to-slf4j" api "org.springframework.boot:spring-boot-starter-logging" + implementation "org.springframework:spring-core" implementation "org.codehaus.janino:janino" testImplementation project(":spring-geode-starter-test") diff --git a/spring-geode-project/spring-geode-starters/spring-geode-starter-logging/src/main/java/org/springframework/geode/logging/slf4j/logback/support/LogbackSupport.java b/spring-geode-project/spring-geode-starters/spring-geode-starter-logging/src/main/java/org/springframework/geode/logging/slf4j/logback/support/LogbackSupport.java index b3d145e3..625fc6e0 100644 --- a/spring-geode-project/spring-geode-starters/spring-geode-starter-logging/src/main/java/org/springframework/geode/logging/slf4j/logback/support/LogbackSupport.java +++ b/spring-geode-project/spring-geode-starters/spring-geode-starter-logging/src/main/java/org/springframework/geode/logging/slf4j/logback/support/LogbackSupport.java @@ -20,10 +20,11 @@ import java.util.Objects; import java.util.Optional; import java.util.function.Function; +import org.springframework.util.ClassUtils; + import org.slf4j.ILoggerFactory; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import org.slf4j.impl.StaticLoggerBinder; import ch.qos.logback.classic.LoggerContext; import ch.qos.logback.classic.spi.ILoggingEvent; @@ -43,6 +44,11 @@ import ch.qos.logback.core.Appender; @SuppressWarnings("unused") public abstract class LogbackSupport { + private static final String STATIC_LOGGER_BINDER_CLASSNAME = "org.slf4j.impl.StaticLoggerBinder"; + + private static final boolean STATIC_LOGGER_BINDER_CLASS_PRESENT = + ClassUtils.isPresent(STATIC_LOGGER_BINDER_CLASSNAME, ClassUtils.getDefaultClassLoader()); + protected static final Function> slf4jLoggerToLogbackLoggerConverter = logger -> Optional.ofNullable(logger) .filter(ch.qos.logback.classic.Logger.class::isInstance) @@ -102,10 +108,16 @@ public abstract class LogbackSupport { private static void resetStaticLoggerBinder() throws Exception { - Method staticLoggerBinderReset = StaticLoggerBinder.class.getDeclaredMethod("reset"); + if (STATIC_LOGGER_BINDER_CLASS_PRESENT) { - staticLoggerBinderReset.setAccessible(true); - staticLoggerBinderReset.invoke(null); + Class staticLoggerBinderClass = + ClassUtils.forName(STATIC_LOGGER_BINDER_CLASSNAME, ClassUtils.getDefaultClassLoader()); + + Method staticLoggerBinderReset = staticLoggerBinderClass.getDeclaredMethod("reset"); + + staticLoggerBinderReset.setAccessible(true); + staticLoggerBinderReset.invoke(null); + } } /**