use of org.apache.logging.log4j.core.config.Configuration in project hive by apache.
the class TestOperationLoggingLayout method checkAppenderState.
/**
* assert that the appender for the given queryId is in the expected state.
* @param msg a diagnostic
* @param routingAppenderName name of the RoutingAppender
* @param queryId the query id to use as a key
* @param expectedStopped the expected stop state
*/
private void checkAppenderState(String msg, String routingAppenderName, String queryId, boolean expectedStopped) throws NoSuchFieldException, IllegalAccessException {
LoggerContext context = (LoggerContext) LogManager.getContext(false);
Configuration configuration = context.getConfiguration();
LoggerConfig loggerConfig = configuration.getRootLogger();
Map<String, Appender> appendersMap = loggerConfig.getAppenders();
RoutingAppender routingAppender = (RoutingAppender) appendersMap.get(routingAppenderName);
Assert.assertNotNull(msg + "could not find routingAppender " + routingAppenderName, routingAppender);
Field defaultsField = RoutingAppender.class.getDeclaredField("appenders");
defaultsField.setAccessible(true);
ConcurrentHashMap appenders = (ConcurrentHashMap) defaultsField.get(routingAppender);
AppenderControl appenderControl = (AppenderControl) appenders.get(queryId);
if (!expectedStopped) {
Assert.assertNotNull(msg + "Could not find AppenderControl for query id " + queryId, appenderControl);
Appender appender = appenderControl.getAppender();
Assert.assertNotNull(msg + "could not find Appender for query id " + queryId + " from AppenderControl " + appenderControl, appender);
Assert.assertEquals(msg + "Appender for query is in unexpected state", expectedStopped, appender.isStopped());
} else {
Assert.assertNull(msg + "AppenderControl for query id is not removed" + queryId, appenderControl);
}
}
use of org.apache.logging.log4j.core.config.Configuration in project herd by FINRAOS.
the class Log4j2LoggingHelper method executeWithoutLogging.
@Override
public void executeWithoutLogging(List<Class<?>> loggingClasses, Command command) throws Exception {
// Get the logger context and it's associated configuration.
LoggerContext loggerContext = (LoggerContext) LogManager.getContext(false);
Configuration configuration = loggerContext.getConfiguration();
// Temporarily turn off logging.
Map<LoggerConfig, Level> loggerToOriginalLevel = new HashMap<>();
for (Class<?> loggingClass : loggingClasses) {
LoggerConfig loggerConfig = loggingClass == null ? null : configuration.getLoggerConfig(loggingClass.getName());
Level originalLevel = loggerConfig == null ? null : loggerConfig.getLevel();
if (loggerConfig != null) {
loggerConfig.setLevel(Level.OFF);
loggerToOriginalLevel.put(loggerConfig, originalLevel);
}
}
// This causes all Loggers to re-fetch information from their LoggerConfig.
loggerContext.updateLoggers();
try {
// Execute the command.
command.execute();
} finally {
for (Map.Entry<LoggerConfig, Level> entry : loggerToOriginalLevel.entrySet()) {
LoggerConfig loggerConfig = entry.getKey();
Level originalLevel = entry.getValue();
// Turn the original logging back on.
loggerConfig.setLevel(originalLevel);
}
}
}
use of org.apache.logging.log4j.core.config.Configuration in project herd by FINRAOS.
the class Log4j2LoggingHelper method getLogLevel.
@Override
public LogLevel getLogLevel(String loggerName) {
// Get the main logger context.
LoggerContext loggerContext = (LoggerContext) LogManager.getContext(false);
// Get the main configuration.
Configuration configuration = loggerContext.getConfiguration();
// Get the logging configuration for the specified logger name from the main configuration.
LoggerConfig loggerConfig = configuration.getLoggerConfig(loggerName);
// Return the logging level for the logging configuration.
return log4jToGenericLogLevel(loggerConfig.getLevel());
}
use of org.apache.logging.log4j.core.config.Configuration in project herd by FINRAOS.
the class Log4j2LoggingHelper method removeLoggingAppender.
@Override
public void removeLoggingAppender(String appenderName) {
// Get the configuration and remove the appender from it.
final LoggerContext loggerContext = (LoggerContext) LogManager.getContext(false);
final Configuration configuration = loggerContext.getConfiguration();
configuration.getRootLogger().removeAppender(appenderName);
}
use of org.apache.logging.log4j.core.config.Configuration in project jmeter-plugins-manager by undera.
the class LoggingConfigurator method configure.
public void configure() {
PatternLayout.Builder patternBuilder = PatternLayout.newBuilder();
patternBuilder.withPattern("%d %p %c{1.}: %m%n");
PatternLayout layout = patternBuilder.build();
ConsoleAppender consoleAppender = ConsoleAppender.createDefaultAppenderForLayout(layout);
consoleAppender.start();
Configuration configuration = ((LoggerContext) LogManager.getContext(false)).getConfiguration();
LoggerConfig rootLogger = configuration.getRootLogger();
rootLogger.setLevel(Level.INFO);
rootLogger.addAppender(consoleAppender, Level.INFO, null);
}
Aggregations