Search in sources :

Example 16 with Configuration

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

the class ShutdownDisabledTest method testShutdownFlag.

@Test
public void testShutdownFlag() {
    final Configuration config = context.getConfiguration();
    assertNotNull("No configuration", config);
    assertFalse("Shutdown hook is enabled", config.isShutdownHookEnabled());
}
Also used : Configuration(org.apache.logging.log4j.core.config.Configuration) Test(org.junit.Test)

Example 17 with Configuration

use of org.apache.logging.log4j.core.config.Configuration 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!");
}
Also used : Appender(org.apache.logging.log4j.core.Appender) ThresholdFilter(org.apache.logging.log4j.core.filter.ThresholdFilter) Configuration(org.apache.logging.log4j.core.config.Configuration) Filter(org.apache.logging.log4j.core.Filter) ThresholdFilter(org.apache.logging.log4j.core.filter.ThresholdFilter) Logger(org.apache.logging.log4j.Logger) LoggerConfig(org.apache.logging.log4j.core.config.LoggerConfig) Test(org.junit.Test)

Example 18 with Configuration

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

the class StructuredDataFilterTest method testConfig.

@Test
public void testConfig() {
    final Configuration config = context.getConfiguration();
    final Filter filter = config.getFilter();
    assertNotNull("No StructuredDataFilter", filter);
    assertTrue("Not a StructuredDataFilter", filter instanceof StructuredDataFilter);
    final StructuredDataFilter sdFilter = (StructuredDataFilter) filter;
    assertFalse("Should not be And filter", sdFilter.isAnd());
    final Map<String, List<String>> map = sdFilter.getMap();
    assertNotNull("No Map", map);
    assertFalse("No elements in Map", map.isEmpty());
    assertEquals("Incorrect number of elements in Map", 1, map.size());
    assertTrue("Map does not contain key eventId", map.containsKey("eventId"));
    assertEquals("List does not contain 2 elements", 2, map.get("eventId").size());
}
Also used : Configuration(org.apache.logging.log4j.core.config.Configuration) Filter(org.apache.logging.log4j.core.Filter) List(java.util.List) Test(org.junit.Test)

Example 19 with Configuration

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

the class LogService method isUsingGemFireDefaultConfig.

public static boolean isUsingGemFireDefaultConfig() {
    final Configuration config = ((org.apache.logging.log4j.core.Logger) LogManager.getLogger(ROOT_LOGGER_NAME, GemFireParameterizedMessageFactory.INSTANCE)).getContext().getConfiguration();
    final StrSubstitutor sub = config.getStrSubstitutor();
    final StrLookup resolver = sub.getVariableResolver();
    final String value = resolver.lookup(GEMFIRE_DEFAULT_PROPERTY);
    return "true".equals(value);
}
Also used : StrSubstitutor(org.apache.logging.log4j.core.lookup.StrSubstitutor) Configuration(org.apache.logging.log4j.core.config.Configuration) StrLookup(org.apache.logging.log4j.core.lookup.StrLookup)

Example 20 with Configuration

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

the class Configurator method getLoggerConfig.

public static LoggerConfig getLoggerConfig(final String name) {
    LoggerContext context = (LoggerContext) LogManager.getContext(false);
    Configuration config = context.getConfiguration();
    LoggerConfig logConfig = config.getLoggerConfig(name);
    if (!logConfig.getName().equals(name)) {
        throw new IllegalStateException("LoggerConfig does not exist for " + name);
    }
    return logConfig;
}
Also used : Configuration(org.apache.logging.log4j.core.config.Configuration) LoggerContext(org.apache.logging.log4j.core.LoggerContext) LoggerConfig(org.apache.logging.log4j.core.config.LoggerConfig)

Aggregations

Configuration (org.apache.logging.log4j.core.config.Configuration)210 LoggerContext (org.apache.logging.log4j.core.LoggerContext)120 LoggerConfig (org.apache.logging.log4j.core.config.LoggerConfig)71 Test (org.junit.Test)54 Appender (org.apache.logging.log4j.core.Appender)50 DefaultConfiguration (org.apache.logging.log4j.core.config.DefaultConfiguration)37 Test (org.junit.jupiter.api.Test)29 FileAppender (org.apache.logging.log4j.core.appender.FileAppender)22 File (java.io.File)21 RollingFileAppender (org.apache.logging.log4j.core.appender.RollingFileAppender)20 Path (java.nio.file.Path)14 Map (java.util.Map)14 ArrayList (java.util.ArrayList)13 Level (org.apache.logging.log4j.Level)13 ListAppender (org.apache.log4j.ListAppender)12 ConsoleAppender (org.apache.logging.log4j.core.appender.ConsoleAppender)12 ConfigurationSource (org.apache.logging.log4j.core.config.ConfigurationSource)12 PatternLayout (org.apache.logging.log4j.core.layout.PatternLayout)11 AbstractLogger (org.apache.logging.log4j.spi.AbstractLogger)11 InputStream (java.io.InputStream)10