use of org.apache.logging.log4j.core.filter.ThresholdFilter in project logging-log4j2 by apache.
the class ConfigurationAssemblerTest method validate.
private void validate(final Configuration config) {
assertNotNull(config);
assertNotNull(config.getName());
assertFalse(config.getName().isEmpty());
assertNotNull("No configuration created", config);
assertEquals("Incorrect State: " + config.getState(), config.getState(), LifeCycle.State.STARTED);
final Map<String, Appender> appenders = config.getAppenders();
assertNotNull(appenders);
assertTrue("Incorrect number of Appenders: " + appenders.size(), appenders.size() == 2);
final KafkaAppender kafkaAppender = (KafkaAppender) appenders.get("Kafka");
final GelfLayout gelfLayout = (GelfLayout) kafkaAppender.getLayout();
final Map<String, LoggerConfig> loggers = config.getLoggers();
assertNotNull(loggers);
assertTrue("Incorrect number of LoggerConfigs: " + loggers.size(), loggers.size() == 2);
final LoggerConfig rootLoggerConfig = loggers.get("");
assertEquals(Level.ERROR, rootLoggerConfig.getLevel());
assertFalse(rootLoggerConfig.isIncludeLocation());
final LoggerConfig loggerConfig = loggers.get("org.apache.logging.log4j");
assertEquals(Level.DEBUG, loggerConfig.getLevel());
assertTrue(loggerConfig.isIncludeLocation());
final Filter filter = config.getFilter();
assertNotNull("No Filter", filter);
assertTrue("Not a Threshold Filter", filter instanceof ThresholdFilter);
final List<CustomLevelConfig> customLevels = config.getCustomLevels();
assertNotNull("No CustomLevels", filter);
assertEquals(1, customLevels.size());
final CustomLevelConfig customLevel = customLevels.get(0);
assertEquals("Panic", customLevel.getLevelName());
assertEquals(17, customLevel.getIntLevel());
final Logger logger = LogManager.getLogger(getClass());
logger.info("Welcome to Log4j!");
}
use of org.apache.logging.log4j.core.filter.ThresholdFilter in project logging-log4j2 by apache.
the class CustomLevelsWithFiltersTest method testConfiguration.
@Test
public void testConfiguration() {
final Configuration configuration = context.getConfiguration();
assertNotNull(configuration);
final FileAppender appender = configuration.getAppender("info");
assertNotNull(appender);
final CompositeFilter compFilter = (CompositeFilter) appender.getFilter();
assertNotNull(compFilter);
final Filter[] filters = compFilter.getFiltersArray();
assertNotNull(filters);
boolean foundLevel = false;
for (final Filter filter : filters) {
final ThresholdFilter tFilter = (ThresholdFilter) filter;
if (infom1Level.equals(tFilter.getLevel())) {
foundLevel = true;
break;
}
}
Assert.assertTrue("Level not found: " + infom1Level, foundLevel);
}
use of org.apache.logging.log4j.core.filter.ThresholdFilter in project logging-log4j2 by apache.
the class PropertiesConfigurationRootLoggerOnlyTest method testPropertiesConfiguration.
@Test
public void testPropertiesConfiguration() {
final Configuration config = context.getConfiguration();
assertNotNull("No configuration created", config);
assertEquals("Incorrect State: " + config.getState(), config.getState(), LifeCycle.State.STARTED);
final Map<String, Appender> appenders = config.getAppenders();
assertNotNull(appenders);
assertTrue("Incorrect number of Appenders: " + appenders.size(), appenders.size() == 1);
final Map<String, LoggerConfig> loggers = config.getLoggers();
assertNotNull(loggers);
assertTrue("Incorrect number of LoggerConfigs: " + loggers.size(), loggers.size() == 1);
final Filter filter = config.getFilter();
assertNotNull("No Filter", filter);
assertTrue("Not a Threshold Filter", filter instanceof ThresholdFilter);
final Logger logger = LogManager.getLogger(getClass());
logger.info("Welcome to Log4j!");
}
use of org.apache.logging.log4j.core.filter.ThresholdFilter in project logging-log4j2 by apache.
the class PropertiesConfigurationTest method testPropertiesConfiguration.
@Test
public void testPropertiesConfiguration() {
final Configuration config = context.getConfiguration();
assertNotNull("No configuration created", config);
assertEquals("Incorrect State: " + config.getState(), config.getState(), LifeCycle.State.STARTED);
final Map<String, Appender> appenders = config.getAppenders();
assertNotNull(appenders);
assertTrue("Incorrect number of Appenders: " + appenders.size(), appenders.size() == 1);
final Map<String, LoggerConfig> loggers = config.getLoggers();
assertNotNull(loggers);
assertTrue("Incorrect number of LoggerConfigs: " + loggers.size(), loggers.size() == 2);
final Filter filter = config.getFilter();
assertNotNull("No Filter", filter);
assertTrue("Not a Threshold Filter", filter instanceof ThresholdFilter);
final Logger logger = LogManager.getLogger(getClass());
logger.info("Welcome to Log4j!");
}
use of org.apache.logging.log4j.core.filter.ThresholdFilter in project logging-log4j2 by apache.
the class RollingFilePropertiesTest method testPropertiesConfiguration.
@Test
public void testPropertiesConfiguration() {
final Configuration config = context.getConfiguration();
assertNotNull("No configuration created", config);
assertEquals("Incorrect State: " + config.getState(), config.getState(), LifeCycle.State.STARTED);
final Map<String, Appender> appenders = config.getAppenders();
assertNotNull(appenders);
assertTrue("Incorrect number of Appenders: " + appenders.size(), appenders.size() == 3);
final Map<String, LoggerConfig> loggers = config.getLoggers();
assertNotNull(loggers);
assertTrue("Incorrect number of LoggerConfigs: " + loggers.size(), loggers.size() == 2);
final Filter filter = config.getFilter();
assertNotNull("No Filter", filter);
assertTrue("Not a Threshold Filter", filter instanceof ThresholdFilter);
final Logger logger = LogManager.getLogger(getClass());
logger.info("Welcome to Log4j!");
}
Aggregations