Adapt to API changes in SLF4J 2.0 and Logback 1.4.
This commit is contained in:
@@ -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")
|
||||
|
||||
@@ -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<Logger, Optional<ch.qos.logback.classic.Logger>> 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);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user