use of org.apache.logging.log4j.core.LoggerContext in project graylog2-server by Graylog2.
the class LoggersResource method getAppender.
private Appender getAppender(final String appenderName) {
final LoggerContext loggerContext = (LoggerContext) LogManager.getContext(false);
final Configuration configuration = loggerContext.getConfiguration();
return configuration.getAppender(appenderName);
}
use of org.apache.logging.log4j.core.LoggerContext in project spring-boot by spring-projects.
the class Log4J2LoggingSystem method beforeInitialize.
@Override
public void beforeInitialize() {
LoggerContext loggerContext = getLoggerContext();
if (isAlreadyInitialized(loggerContext)) {
return;
}
super.beforeInitialize();
loggerContext.getConfiguration().addFilter(FILTER);
}
use of org.apache.logging.log4j.core.LoggerContext in project spring-boot by spring-projects.
the class Log4J2LoggingSystem method initialize.
@Override
public void initialize(LoggingInitializationContext initializationContext, String configLocation, LogFile logFile) {
LoggerContext loggerContext = getLoggerContext();
if (isAlreadyInitialized(loggerContext)) {
return;
}
loggerContext.getConfiguration().removeFilter(FILTER);
super.initialize(initializationContext, configLocation, logFile);
markAsInitialized(loggerContext);
}
use of org.apache.logging.log4j.core.LoggerContext in project spring-boot by spring-projects.
the class Log4J2LoggingSystemTests method initializationIsOnlyPerformedOnceUntilCleanedUp.
@Test
public void initializationIsOnlyPerformedOnceUntilCleanedUp() throws Exception {
LoggerContext loggerContext = (LoggerContext) LogManager.getContext(false);
PropertyChangeListener listener = mock(PropertyChangeListener.class);
loggerContext.addPropertyChangeListener(listener);
this.loggingSystem.beforeInitialize();
this.loggingSystem.initialize(null, null, null);
this.loggingSystem.beforeInitialize();
this.loggingSystem.initialize(null, null, null);
this.loggingSystem.beforeInitialize();
this.loggingSystem.initialize(null, null, null);
verify(listener, times(2)).propertyChange(any(PropertyChangeEvent.class));
this.loggingSystem.cleanUp();
this.loggingSystem.beforeInitialize();
this.loggingSystem.initialize(null, null, null);
verify(listener, times(4)).propertyChange(any(PropertyChangeEvent.class));
}
use of org.apache.logging.log4j.core.LoggerContext in project camel by apache.
the class ConsumingAppender method newAppender.
public static Appender newAppender(String loggerName, String appenderName, String patter, Level level, Consumer<LogEvent> consumer) {
final LoggerContext ctx = (LoggerContext) LogManager.getContext(false);
final Configuration config = ctx.getConfiguration();
config.removeLogger(loggerName);
ConsumingAppender appender = new ConsumingAppender(appenderName, patter, consumer);
appender.start();
LoggerConfig loggerConfig = LoggerConfig.createLogger(true, level, loggerName, "true", new AppenderRef[] { AppenderRef.createAppenderRef(appenderName, null, null) }, null, config, null);
loggerConfig.addAppender(appender, null, null);
config.addLogger(loggerName, loggerConfig);
ctx.updateLoggers();
return appender;
}
Aggregations