Search in sources :

Example 1 with CustomLevelConfig

use of org.apache.logging.log4j.core.config.CustomLevelConfig 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!");
}
Also used : KafkaAppender(org.apache.logging.log4j.core.appender.mom.kafka.KafkaAppender) Appender(org.apache.logging.log4j.core.Appender) ThresholdFilter(org.apache.logging.log4j.core.filter.ThresholdFilter) Filter(org.apache.logging.log4j.core.Filter) ThresholdFilter(org.apache.logging.log4j.core.filter.ThresholdFilter) KafkaAppender(org.apache.logging.log4j.core.appender.mom.kafka.KafkaAppender) GelfLayout(org.apache.logging.log4j.core.layout.GelfLayout) Logger(org.apache.logging.log4j.Logger) CustomLevelConfig(org.apache.logging.log4j.core.config.CustomLevelConfig) LoggerConfig(org.apache.logging.log4j.core.config.LoggerConfig)

Aggregations

Logger (org.apache.logging.log4j.Logger)1 Appender (org.apache.logging.log4j.core.Appender)1 Filter (org.apache.logging.log4j.core.Filter)1 KafkaAppender (org.apache.logging.log4j.core.appender.mom.kafka.KafkaAppender)1 CustomLevelConfig (org.apache.logging.log4j.core.config.CustomLevelConfig)1 LoggerConfig (org.apache.logging.log4j.core.config.LoggerConfig)1 ThresholdFilter (org.apache.logging.log4j.core.filter.ThresholdFilter)1 GelfLayout (org.apache.logging.log4j.core.layout.GelfLayout)1