|
|
|
@ -58,8 +58,10 @@ import org.springframework.boot.logging.LoggerConfiguration;
|
|
|
|
|
import org.springframework.boot.logging.LoggingInitializationContext;
|
|
|
|
|
import org.springframework.boot.logging.LoggingSystem;
|
|
|
|
|
import org.springframework.boot.logging.LoggingSystemFactory;
|
|
|
|
|
import org.springframework.core.Conventions;
|
|
|
|
|
import org.springframework.core.Ordered;
|
|
|
|
|
import org.springframework.core.annotation.Order;
|
|
|
|
|
import org.springframework.core.env.Environment;
|
|
|
|
|
import org.springframework.util.Assert;
|
|
|
|
|
import org.springframework.util.ClassUtils;
|
|
|
|
|
import org.springframework.util.CollectionUtils;
|
|
|
|
@ -84,6 +86,9 @@ public class Log4J2LoggingSystem extends AbstractLoggingSystem {
|
|
|
|
|
|
|
|
|
|
private static final String LOG4J_LOG_MANAGER = "org.apache.logging.log4j.jul.LogManager";
|
|
|
|
|
|
|
|
|
|
static final String ENVIRONMENT_KEY = Conventions.getQualifiedAttributeName(Log4J2LoggingSystem.class,
|
|
|
|
|
"environment");
|
|
|
|
|
|
|
|
|
|
private static final LogLevels<Level> LEVELS = new LogLevels<>();
|
|
|
|
|
|
|
|
|
|
static {
|
|
|
|
@ -227,6 +232,8 @@ public class Log4J2LoggingSystem extends AbstractLoggingSystem {
|
|
|
|
|
if (isAlreadyInitialized(loggerContext)) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
Environment environment = initializationContext.getEnvironment();
|
|
|
|
|
getLoggerContext().putObjectIfAbsent(ENVIRONMENT_KEY, environment);
|
|
|
|
|
loggerContext.getConfiguration().removeFilter(FILTER);
|
|
|
|
|
super.initialize(initializationContext, configLocation, logFile);
|
|
|
|
|
markAsInitialized(loggerContext);
|
|
|
|
@ -467,6 +474,17 @@ public class Log4J2LoggingSystem extends AbstractLoggingSystem {
|
|
|
|
|
loggerContext.setExternalContext(null);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Get the Spring {@link Environment} attached to the given {@link LoggerContext} or
|
|
|
|
|
* {@code null} if no environment is available.
|
|
|
|
|
* @param loggerContext the logger context
|
|
|
|
|
* @return the Spring {@link Environment} or {@code null}
|
|
|
|
|
* @since 3.0.0
|
|
|
|
|
*/
|
|
|
|
|
public static Environment getEnvironment(LoggerContext loggerContext) {
|
|
|
|
|
return (Environment) ((loggerContext != null) ? loggerContext.getObject(ENVIRONMENT_KEY) : null);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* {@link LoggingSystemFactory} that returns {@link Log4J2LoggingSystem} if possible.
|
|
|
|
|
*/
|
|
|
|
|