public abstract class LogbackSupport
extends java.lang.Object
ILoggerFactory
,
Logger
,
LoggerFactory
,
LoggerContext
,
Appender
Modifier and Type | Field and Description |
---|---|
protected static java.lang.String |
CONSOLE_APPENDER_NAME |
protected static java.lang.String |
DELEGATE_APPENDER_NAME |
protected static java.lang.String |
ILLEGAL_LOGGER_TYPE_EXCEPTION_MESSAGE |
protected static java.lang.String |
ROOT_LOGGER_NAME |
protected static java.util.function.Function<org.slf4j.Logger,java.util.Optional<ch.qos.logback.classic.Logger>> |
slf4jLoggerToLogbackLoggerConverter |
protected static java.lang.String |
SPRING_BOOT_LOGGING_SYSTEM_CLASS_NAME |
protected static java.lang.String |
UNRESOLVABLE_APPENDER_EXCEPTION_MESSAGE |
Constructor and Description |
---|
LogbackSupport() |
Modifier and Type | Method and Description |
---|---|
static boolean |
addAppender(ch.qos.logback.classic.Logger logger,
ch.qos.logback.core.Appender<ch.qos.logback.classic.spi.ILoggingEvent> appender)
Adds the given
Appender to the given Logger . |
static boolean |
removeAppender(ch.qos.logback.classic.Logger logger,
java.lang.String appenderName)
Removes the
Appender with the specified name from the given Logger . |
static boolean |
removeConsoleAppender(ch.qos.logback.classic.Logger logger)
Removes the console
Appender from the given Logger . |
static boolean |
removeDelegateAppender(ch.qos.logback.classic.Logger logger)
Removes the delegate
Appender from the given Logger . |
static <E,T extends ch.qos.logback.core.Appender<E>> |
requireAppender(ch.qos.logback.classic.Logger logger,
java.lang.String appenderName,
java.lang.Class<T> appenderType)
Requires an
Appender with the given name having the specified type
from the given Logger . |
static ch.qos.logback.classic.Logger |
requireLogbackRootLogger()
Requires the SLF4J Logback ROOT
Logger otherwise throws an IllegalStateException . |
static ch.qos.logback.classic.LoggerContext |
requireLoggerContext()
Requires a
LoggerContext otherwise throws an IllegalStateException . |
static void |
resetLogback()
Resets the state of the SLF4J Logback logging provider and system.
|
static <E,T extends ch.qos.logback.core.Appender<E>> |
resolveAppender(ch.qos.logback.classic.Logger logger,
java.lang.String appenderName,
java.lang.Class<T> appenderType)
Finds an
Appender with the given name from the given Logger . |
static java.util.Optional<ch.qos.logback.classic.LoggerContext> |
resolveLoggerContext()
Resolves the SLF4J, Logback
LoggerContext . |
static java.util.Optional<org.slf4j.Logger> |
resolveRootLogger()
Resolves the
Root Logger . |
static void |
stopLogback()
Properly stops Logback classic.
|
static void |
suppressSpringBootLogbackInitialization()
Disables Spring Boot's logging initialization, auto-configuration.
|
static java.util.Optional<ch.qos.logback.classic.Logger> |
toLogbackLogger(org.slf4j.Logger logger)
Converts an SLF4J
Logger to a Logback Logger . |
protected static final java.util.function.Function<org.slf4j.Logger,java.util.Optional<ch.qos.logback.classic.Logger>> slf4jLoggerToLogbackLoggerConverter
protected static final java.lang.String CONSOLE_APPENDER_NAME
protected static final java.lang.String DELEGATE_APPENDER_NAME
protected static final java.lang.String ILLEGAL_LOGGER_TYPE_EXCEPTION_MESSAGE
protected static final java.lang.String ROOT_LOGGER_NAME
protected static final java.lang.String SPRING_BOOT_LOGGING_SYSTEM_CLASS_NAME
protected static final java.lang.String UNRESOLVABLE_APPENDER_EXCEPTION_MESSAGE
public static void suppressSpringBootLogbackInitialization()
public static void stopLogback()
public static void resetLogback()
public static java.util.Optional<ch.qos.logback.classic.LoggerContext> resolveLoggerContext()
LoggerContext
.
If the LoggerContext
could not be resolve then the returned Optional
will be empty
.Optional
LoggerContext
.LoggerContext
public static ch.qos.logback.classic.LoggerContext requireLoggerContext()
LoggerContext
otherwise throws an IllegalStateException
.LoggerContext
.java.lang.IllegalStateException
- if the LoggerContext
could not be resolved.resolveLoggerContext()
public static java.util.Optional<org.slf4j.Logger> resolveRootLogger()
Root
Logger
.Optional
Logger
for the logging provider's ROOT Logger
.Logger
public static ch.qos.logback.classic.Logger requireLogbackRootLogger()
Logger
otherwise throws an IllegalStateException
.Logger
.java.lang.IllegalStateException
- if the SLF4J Logback ROOT Logger
could not be resolved
or the ROOT Logger
is not a SLF4J Logback ROOT Logger
.Logger
,
resolveRootLogger()
public static <E,T extends ch.qos.logback.core.Appender<E>> java.util.Optional<T> resolveAppender(ch.qos.logback.classic.Logger logger, java.lang.String appenderName, java.lang.Class<T> appenderType)
Appender
with the given name
from the given Logger
.T
- type
of the Appender
.E
- type
of the logging event.logger
- SLF4J Logger
from which to resolve the Appender
.appenderName
- a String
containing the name of the Appender
to resolve.appenderType
- required type
of the Appender
to resolve.Optional
Appender
with the given name
from the Logger
.Appender
,
Optional
,
Logger
public static <E,T extends ch.qos.logback.core.Appender<E>> T requireAppender(ch.qos.logback.classic.Logger logger, java.lang.String appenderName, java.lang.Class<T> appenderType)
Appender
with the given name
having the specified type
from the given Logger
.T
- type
of the Appender
.E
- type
of the Objects
processed by the Appender
.logger
- Logger
from which to resolve the Appender
.appenderName
- String
containing the name of the Appender
.appenderType
- required type
of the Appender
.Appender
.java.lang.IllegalStateException
- if an Appender
with name
and required type
could not be resolved from the given Logger
.Logger
,
Appender
public static boolean addAppender(ch.qos.logback.classic.Logger logger, ch.qos.logback.core.Appender<ch.qos.logback.classic.spi.ILoggingEvent> appender)
Appender
to the given Logger
.logger
- Logger
to add the Appender
to.appender
- Appender
to add to the Logger
.Appender
was successfully added to the Logger
.Logger
,
Appender
public static boolean removeAppender(ch.qos.logback.classic.Logger logger, java.lang.String appenderName)
Appender
with the specified name
from the given Logger
.logger
- Logger
from which to remove the Appender
.appenderName
- name
of the Appender
to remove from the Logger
.Appender
was removed from
the given Logger
.Logger
,
Appender
public static boolean removeConsoleAppender(ch.qos.logback.classic.Logger logger)
Appender
from the given Logger
.logger
- Logger
from which to remove the console Appender
.Appender
was registered with
and successfully remove from the given Logger
.removeAppender(ch.qos.logback.classic.Logger, String)
public static boolean removeDelegateAppender(ch.qos.logback.classic.Logger logger)
Appender
from the given Logger
.logger
- Logger
from which to remove the delegate Appender
.Appender
was registered with
and successfully remove from the given Logger
.removeAppender(ch.qos.logback.classic.Logger, String)
public static java.util.Optional<ch.qos.logback.classic.Logger> toLogbackLogger(org.slf4j.Logger logger)
Logger
to a Logback Logger
.logger
- SLF4J Logger
to convert.Optional
Logback Logger
for the given SLF4J Logger
iff the SLF4J Logger
is not-null and is a Logback Logger
.Optional
,
Logger
,
Logger