Search in sources :

Example 86 with Configuration

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

the class PatternParserTest method testNanoPatternLongChangesNanoClockFactoryMode.

@Test
public void testNanoPatternLongChangesNanoClockFactoryMode() {
    final Configuration config = new NullConfiguration();
    assertTrue(config.getNanoClock() instanceof DummyNanoClock);
    final PatternParser pp = new PatternParser(config, KEY, null);
    assertTrue(config.getNanoClock() instanceof DummyNanoClock);
    pp.parse("%m");
    assertTrue(config.getNanoClock() instanceof DummyNanoClock);
    pp.parse("%N");
    assertTrue(config.getNanoClock() instanceof SystemNanoClock);
}
Also used : SystemNanoClock(org.apache.logging.log4j.core.util.SystemNanoClock) NullConfiguration(org.apache.logging.log4j.core.config.NullConfiguration) Configuration(org.apache.logging.log4j.core.config.Configuration) DummyNanoClock(org.apache.logging.log4j.core.util.DummyNanoClock) NullConfiguration(org.apache.logging.log4j.core.config.NullConfiguration) Test(org.junit.Test)

Example 87 with Configuration

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

the class PatternParserTest method testNanoPatternShortChangesConfigurationNanoClock.

@Test
public void testNanoPatternShortChangesConfigurationNanoClock() {
    final Configuration config = new NullConfiguration();
    assertTrue(config.getNanoClock() instanceof DummyNanoClock);
    final PatternParser pp = new PatternParser(config, KEY, null);
    assertTrue(config.getNanoClock() instanceof DummyNanoClock);
    pp.parse("%m");
    assertTrue(config.getNanoClock() instanceof DummyNanoClock);
    // this changes the config clock
    pp.parse("%nano");
    assertTrue(config.getNanoClock() instanceof SystemNanoClock);
}
Also used : SystemNanoClock(org.apache.logging.log4j.core.util.SystemNanoClock) NullConfiguration(org.apache.logging.log4j.core.config.NullConfiguration) Configuration(org.apache.logging.log4j.core.config.Configuration) DummyNanoClock(org.apache.logging.log4j.core.util.DummyNanoClock) NullConfiguration(org.apache.logging.log4j.core.config.NullConfiguration) Test(org.junit.Test)

Example 88 with Configuration

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

the class LoggerTest method testLevelInheritence.

@Test
public void testLevelInheritence() throws Exception {
    final Configuration config = context.getConfiguration();
    final LoggerConfig loggerConfig = config.getLoggerConfig("org.apache.logging.log4j.core.LoggerTest");
    assertNotNull(loggerConfig);
    assertEquals(loggerConfig.getName(), "org.apache.logging.log4j.core.LoggerTest");
    assertEquals(loggerConfig.getLevel(), Level.DEBUG);
    final Logger localLogger = context.getLogger("org.apache.logging.log4j.core.LoggerTest");
    assertTrue("Incorrect level - expected DEBUG, actual " + localLogger.getLevel(), localLogger.getLevel() == Level.DEBUG);
}
Also used : Configuration(org.apache.logging.log4j.core.config.Configuration) AbstractLogger(org.apache.logging.log4j.spi.AbstractLogger) LoggerConfig(org.apache.logging.log4j.core.config.LoggerConfig) Test(org.junit.Test)

Example 89 with Configuration

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

the class ShutdownTimeoutConfigurationTest method testShutdownFlag.

@Test
public void testShutdownFlag() {
    final Configuration config = context.getConfiguration();
    assertNotNull("No configuration", config);
    assertEquals(5000, config.getShutdownTimeoutMillis());
}
Also used : Configuration(org.apache.logging.log4j.core.config.Configuration) Test(org.junit.Test)

Example 90 with Configuration

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

the class LateConfigTest method testReconfiguration.

@Test
public void testReconfiguration() throws Exception {
    final Configuration cfg = context.getConfiguration();
    assertNotNull("No configuration", cfg);
    assertTrue("Not set to default configuration", cfg instanceof DefaultConfiguration);
    final File file = new File(CONFIG);
    final LoggerContext loggerContext = LoggerContext.getContext(null, false, file.toURI());
    assertNotNull("No Logger Context", loggerContext);
    final Configuration newConfig = loggerContext.getConfiguration();
    assertTrue("Configuration not reset", cfg != newConfig);
    assertTrue("Reconfiguration failed", newConfig instanceof XmlConfiguration);
    context = LoggerContext.getContext(false);
    final Configuration sameConfig = context.getConfiguration();
    assertTrue("Configuration should not have been reset", newConfig == sameConfig);
}
Also used : DefaultConfiguration(org.apache.logging.log4j.core.config.DefaultConfiguration) XmlConfiguration(org.apache.logging.log4j.core.config.xml.XmlConfiguration) Configuration(org.apache.logging.log4j.core.config.Configuration) DefaultConfiguration(org.apache.logging.log4j.core.config.DefaultConfiguration) XmlConfiguration(org.apache.logging.log4j.core.config.xml.XmlConfiguration) File(java.io.File) Test(org.junit.Test)

Aggregations

Configuration (org.apache.logging.log4j.core.config.Configuration)105 LoggerContext (org.apache.logging.log4j.core.LoggerContext)54 Test (org.junit.Test)43 LoggerConfig (org.apache.logging.log4j.core.config.LoggerConfig)39 Appender (org.apache.logging.log4j.core.Appender)21 DefaultConfiguration (org.apache.logging.log4j.core.config.DefaultConfiguration)15 File (java.io.File)12 FileAppender (org.apache.logging.log4j.core.appender.FileAppender)9 RollingFileAppender (org.apache.logging.log4j.core.appender.RollingFileAppender)9 Path (java.nio.file.Path)7 Level (org.apache.logging.log4j.Level)7 NullConfiguration (org.apache.logging.log4j.core.config.NullConfiguration)7 ArrayList (java.util.ArrayList)6 Logger (org.apache.logging.log4j.Logger)6 Filter (org.apache.logging.log4j.core.Filter)6 AbstractLogger (org.apache.logging.log4j.spi.AbstractLogger)6 PatternLayout (org.apache.logging.log4j.core.layout.PatternLayout)5 ListAppender (org.apache.logging.log4j.test.appender.ListAppender)5 ConsoleAppender (org.apache.logging.log4j.core.appender.ConsoleAppender)4 AppenderRef (org.apache.logging.log4j.core.config.AppenderRef)4