use of org.apache.logging.log4j.core.config.LoggerConfig in project hive by apache.
the class StringAppender method removeFromLogger.
@VisibleForTesting
public void removeFromLogger(String loggerName) {
LoggerConfig loggerConfig = configuration.getLoggerConfig(loggerName);
loggerConfig.removeAppender(APPENDER_NAME);
context.updateLoggers();
}
use of org.apache.logging.log4j.core.config.LoggerConfig in project elasticsearch by elastic.
the class Loggers method findAppender.
public static Appender findAppender(final Logger logger, final Class<? extends Appender> clazz) {
final LoggerContext ctx = (LoggerContext) LogManager.getContext(false);
final Configuration config = ctx.getConfiguration();
final LoggerConfig loggerConfig = config.getLoggerConfig(logger.getName());
for (final Map.Entry<String, Appender> entry : loggerConfig.getAppenders().entrySet()) {
if (entry.getValue().getClass().equals(clazz)) {
return entry.getValue();
}
}
return null;
}
use of org.apache.logging.log4j.core.config.LoggerConfig in project elasticsearch by elastic.
the class Loggers method removeAppender.
public static void removeAppender(final Logger logger, final Appender appender) {
final LoggerContext ctx = (LoggerContext) LogManager.getContext(false);
final Configuration config = ctx.getConfiguration();
LoggerConfig loggerConfig = config.getLoggerConfig(logger.getName());
if (!logger.getName().equals(loggerConfig.getName())) {
loggerConfig = new LoggerConfig(logger.getName(), logger.getLevel(), true);
config.addLogger(logger.getName(), loggerConfig);
}
loggerConfig.removeAppender(appender.getName());
ctx.updateLoggers();
}
use of org.apache.logging.log4j.core.config.LoggerConfig in project elasticsearch by elastic.
the class Loggers method setLevel.
public static void setLevel(Logger logger, Level level) {
if (!LogManager.ROOT_LOGGER_NAME.equals(logger.getName())) {
Configurator.setLevel(logger.getName(), level);
} else {
final LoggerContext ctx = LoggerContext.getContext(false);
final Configuration config = ctx.getConfiguration();
final LoggerConfig loggerConfig = config.getLoggerConfig(logger.getName());
loggerConfig.setLevel(level);
ctx.updateLoggers();
}
// we have to descend the hierarchy
final LoggerContext ctx = LoggerContext.getContext(false);
for (final LoggerConfig loggerConfig : ctx.getConfiguration().getLoggers().values()) {
if (LogManager.ROOT_LOGGER_NAME.equals(logger.getName()) || loggerConfig.getName().startsWith(logger.getName() + ".")) {
Configurator.setLevel(loggerConfig.getName(), level);
}
}
}
use of org.apache.logging.log4j.core.config.LoggerConfig in project elasticsearch by elastic.
the class EvilLoggerConfigurationTests method testResolveMultipleConfigs.
public void testResolveMultipleConfigs() throws Exception {
final Level level = ESLoggerFactory.getLogger("test").getLevel();
try {
final Path configDir = getDataPath("config");
final Settings settings = Settings.builder().put(Environment.PATH_CONF_SETTING.getKey(), configDir.toAbsolutePath()).put(Environment.PATH_HOME_SETTING.getKey(), createTempDir().toString()).build();
final Environment environment = new Environment(settings);
LogConfigurator.configure(environment);
{
final LoggerContext ctx = (LoggerContext) LogManager.getContext(false);
final Configuration config = ctx.getConfiguration();
final LoggerConfig loggerConfig = config.getLoggerConfig("test");
final Appender appender = loggerConfig.getAppenders().get("console");
assertThat(appender, notNullValue());
}
{
final LoggerContext ctx = (LoggerContext) LogManager.getContext(false);
final Configuration config = ctx.getConfiguration();
final LoggerConfig loggerConfig = config.getLoggerConfig("second");
final Appender appender = loggerConfig.getAppenders().get("console2");
assertThat(appender, notNullValue());
}
{
final LoggerContext ctx = (LoggerContext) LogManager.getContext(false);
final Configuration config = ctx.getConfiguration();
final LoggerConfig loggerConfig = config.getLoggerConfig("third");
final Appender appender = loggerConfig.getAppenders().get("console3");
assertThat(appender, notNullValue());
}
} finally {
Configurator.setLevel("test", level);
}
}
Aggregations