|
|
|
@ -47,6 +47,7 @@ import org.apache.logging.log4j.core.net.ssl.SslConfigurationFactory; |
|
|
|
import org.apache.logging.log4j.core.util.AuthorizationProvider; |
|
|
|
import org.apache.logging.log4j.core.util.AuthorizationProvider; |
|
|
|
import org.apache.logging.log4j.core.util.NameUtil; |
|
|
|
import org.apache.logging.log4j.core.util.NameUtil; |
|
|
|
import org.apache.logging.log4j.jul.Log4jBridgeHandler; |
|
|
|
import org.apache.logging.log4j.jul.Log4jBridgeHandler; |
|
|
|
|
|
|
|
import org.apache.logging.log4j.status.StatusConsoleListener; |
|
|
|
import org.apache.logging.log4j.status.StatusLogger; |
|
|
|
import org.apache.logging.log4j.status.StatusLogger; |
|
|
|
import org.apache.logging.log4j.util.PropertiesUtil; |
|
|
|
import org.apache.logging.log4j.util.PropertiesUtil; |
|
|
|
|
|
|
|
|
|
|
|
@ -93,6 +94,9 @@ public class Log4J2LoggingSystem extends AbstractLoggingSystem { |
|
|
|
static final String ENVIRONMENT_KEY = Conventions.getQualifiedAttributeName(Log4J2LoggingSystem.class, |
|
|
|
static final String ENVIRONMENT_KEY = Conventions.getQualifiedAttributeName(Log4J2LoggingSystem.class, |
|
|
|
"environment"); |
|
|
|
"environment"); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static final String STATUS_LISTENER_KEY = Conventions.getQualifiedAttributeName(Log4J2LoggingSystem.class, |
|
|
|
|
|
|
|
"statusListener"); |
|
|
|
|
|
|
|
|
|
|
|
private static final LogLevels<Level> LEVELS = new LogLevels<>(); |
|
|
|
private static final LogLevels<Level> LEVELS = new LogLevels<>(); |
|
|
|
|
|
|
|
|
|
|
|
static { |
|
|
|
static { |
|
|
|
@ -214,10 +218,12 @@ public class Log4J2LoggingSystem extends AbstractLoggingSystem { |
|
|
|
if (isAlreadyInitialized(loggerContext)) { |
|
|
|
if (isAlreadyInitialized(loggerContext)) { |
|
|
|
return; |
|
|
|
return; |
|
|
|
} |
|
|
|
} |
|
|
|
resetFallbackListenerStream(StatusLogger.getLogger()); |
|
|
|
StatusConsoleListener listener = new StatusConsoleListener(Level.WARN); |
|
|
|
|
|
|
|
StatusLogger.getLogger().registerListener(listener); |
|
|
|
|
|
|
|
loggerContext.putObject(STATUS_LISTENER_KEY, listener); |
|
|
|
Environment environment = initializationContext.getEnvironment(); |
|
|
|
Environment environment = initializationContext.getEnvironment(); |
|
|
|
if (environment != null) { |
|
|
|
if (environment != null) { |
|
|
|
getLoggerContext().putObject(ENVIRONMENT_KEY, environment); |
|
|
|
loggerContext.putObject(ENVIRONMENT_KEY, environment); |
|
|
|
Log4J2LoggingSystem.propertySource.setEnvironment(environment); |
|
|
|
Log4J2LoggingSystem.propertySource.setEnvironment(environment); |
|
|
|
PropertiesUtil.getProperties().addPropertySource(Log4J2LoggingSystem.propertySource); |
|
|
|
PropertiesUtil.getProperties().addPropertySource(Log4J2LoggingSystem.propertySource); |
|
|
|
} |
|
|
|
} |
|
|
|
@ -226,21 +232,6 @@ public class Log4J2LoggingSystem extends AbstractLoggingSystem { |
|
|
|
markAsInitialized(loggerContext); |
|
|
|
markAsInitialized(loggerContext); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
|
|
* Reset the stream used by the fallback listener to the current system out. This |
|
|
|
|
|
|
|
* allows the fallback listener to work with any captured output streams in a similar |
|
|
|
|
|
|
|
* way to the {@code follow} attribute of the {@code Console} appender. |
|
|
|
|
|
|
|
* @param statusLogger the status logger to update |
|
|
|
|
|
|
|
*/ |
|
|
|
|
|
|
|
private void resetFallbackListenerStream(StatusLogger statusLogger) { |
|
|
|
|
|
|
|
try { |
|
|
|
|
|
|
|
statusLogger.getFallbackListener().setStream(System.out); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
catch (NoSuchMethodError ex) { |
|
|
|
|
|
|
|
// Ignore for older versions of Log4J
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
@Override |
|
|
|
protected void loadDefaults(LoggingInitializationContext initializationContext, LogFile logFile) { |
|
|
|
protected void loadDefaults(LoggingInitializationContext initializationContext, LogFile logFile) { |
|
|
|
String location = getPackagedConfigFile((logFile != null) ? "log4j2-file.xml" : "log4j2.xml"); |
|
|
|
String location = getPackagedConfigFile((logFile != null) ? "log4j2-file.xml" : "log4j2.xml"); |
|
|
|
@ -454,9 +445,14 @@ public class Log4J2LoggingSystem extends AbstractLoggingSystem { |
|
|
|
super.cleanUp(); |
|
|
|
super.cleanUp(); |
|
|
|
LoggerContext loggerContext = getLoggerContext(); |
|
|
|
LoggerContext loggerContext = getLoggerContext(); |
|
|
|
markAsUninitialized(loggerContext); |
|
|
|
markAsUninitialized(loggerContext); |
|
|
|
|
|
|
|
StatusConsoleListener listener = (StatusConsoleListener) getLoggerContext().getObject(STATUS_LISTENER_KEY); |
|
|
|
|
|
|
|
if (listener != null) { |
|
|
|
|
|
|
|
StatusLogger.getLogger().removeListener(listener); |
|
|
|
|
|
|
|
loggerContext.removeObject(STATUS_LISTENER_KEY); |
|
|
|
|
|
|
|
} |
|
|
|
loggerContext.getConfiguration().removeFilter(FILTER); |
|
|
|
loggerContext.getConfiguration().removeFilter(FILTER); |
|
|
|
Log4J2LoggingSystem.propertySource.setEnvironment(null); |
|
|
|
Log4J2LoggingSystem.propertySource.setEnvironment(null); |
|
|
|
getLoggerContext().removeObject(ENVIRONMENT_KEY); |
|
|
|
loggerContext.removeObject(ENVIRONMENT_KEY); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private LoggerConfig getLogger(String name) { |
|
|
|
private LoggerConfig getLogger(String name) { |
|
|
|
|