Search in sources :

Example 6 with CompositeConfiguration

use of org.apache.logging.log4j.core.config.composite.CompositeConfiguration in project logging-log4j2 by apache.

the class CompositeConfigurationTest method testAttributeMergeForLoggers.

@Test
public void testAttributeMergeForLoggers() {
    final LoggerContextRule lcr = new LoggerContextRule("classpath:log4j-comp-logger-root.xml,log4j-comp-logger-attr-override.json");
    final Statement test = new Statement() {

        @Override
        public void evaluate() throws Throwable {
            final CompositeConfiguration config = (CompositeConfiguration) lcr.getConfiguration();
            //Test for Root log level override
            assertEquals("Expected Root logger log level to be WARN", Level.WARN, config.getRootLogger().getLevel());
            //Test for cat2 level override
            final LoggerConfig cat2 = config.getLogger("cat2");
            assertEquals("Expected cat2 log level to be INFO", Level.INFO, cat2.getLevel());
            //Test for cat2 additivity override
            assertTrue("Expected cat2 additivity to be true", cat2.isAdditive());
            //Regression
            //Check level on cat3 (not present in root config)
            assertEquals("Expected cat3 log level to be ERROR", Level.ERROR, config.getLogger("cat3").getLevel());
            //Check level on cat1 (not present in overriden config)
            assertEquals("Expected cat1 log level to be DEBUG", Level.DEBUG, config.getLogger("cat1").getLevel());
        }
    };
    runTest(lcr, test);
}
Also used : Statement(org.junit.runners.model.Statement) CompositeConfiguration(org.apache.logging.log4j.core.config.composite.CompositeConfiguration) LoggerContextRule(org.apache.logging.log4j.junit.LoggerContextRule) Test(org.junit.Test)

Aggregations

CompositeConfiguration (org.apache.logging.log4j.core.config.composite.CompositeConfiguration)6 LoggerContextRule (org.apache.logging.log4j.junit.LoggerContextRule)4 Test (org.junit.Test)4 Statement (org.junit.runners.model.Statement)4 ArrayList (java.util.ArrayList)2 LoggerContext (org.apache.logging.log4j.core.LoggerContext)2 AbstractConfiguration (org.apache.logging.log4j.core.config.AbstractConfiguration)2 IOException (java.io.IOException)1 URI (java.net.URI)1 FileVisitOption (java.nio.file.FileVisitOption)1 FileVisitResult (java.nio.file.FileVisitResult)1 Path (java.nio.file.Path)1 BasicFileAttributes (java.nio.file.attribute.BasicFileAttributes)1 Appender (org.apache.logging.log4j.core.Appender)1 ConsoleAppender (org.apache.logging.log4j.core.appender.ConsoleAppender)1 FileAppender (org.apache.logging.log4j.core.appender.FileAppender)1 Configuration (org.apache.logging.log4j.core.config.Configuration)1 PropertiesConfiguration (org.apache.logging.log4j.core.config.properties.PropertiesConfiguration)1 PropertiesConfigurationFactory (org.apache.logging.log4j.core.config.properties.PropertiesConfigurationFactory)1 RegexFilter (org.apache.logging.log4j.core.filter.RegexFilter)1