Search in sources :

Example 56 with LoggerConfig

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

the class Log4j1ConfigurationFactoryTest method testFile.

private Layout<?> testFile(final String configResource) throws Exception {
    final Configuration configuration = getConfiguration(configResource);
    final FileAppender appender = configuration.getAppender("File");
    assertNotNull(appender);
    assertEquals("target/mylog.txt", appender.getFileName());
    //
    final LoggerConfig loggerConfig = configuration.getLoggerConfig("com.example.foo");
    assertNotNull(loggerConfig);
    assertEquals(Level.DEBUG, loggerConfig.getLevel());
    configuration.start();
    configuration.stop();
    return appender.getLayout();
}
Also used : FileAppender(org.apache.logging.log4j.core.appender.FileAppender) RollingFileAppender(org.apache.logging.log4j.core.appender.RollingFileAppender) Configuration(org.apache.logging.log4j.core.config.Configuration) LoggerConfig(org.apache.logging.log4j.core.config.LoggerConfig)

Example 57 with LoggerConfig

use of org.apache.logging.log4j.core.config.LoggerConfig 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 58 with LoggerConfig

use of org.apache.logging.log4j.core.config.LoggerConfig 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!");
}
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 59 with LoggerConfig

use of org.apache.logging.log4j.core.config.LoggerConfig 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!");
}
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 60 with LoggerConfig

use of org.apache.logging.log4j.core.config.LoggerConfig in project pyramid by cheng-li.

the class RidgeLogisticTrainerTest method main.

public static void main(String[] args) throws Exception {
    LoggerContext ctx = (LoggerContext) LogManager.getContext(false);
    Configuration config = ctx.getConfiguration();
    LoggerConfig loggerConfig = config.getLoggerConfig(LogManager.ROOT_LOGGER_NAME);
    loggerConfig.setLevel(Level.DEBUG);
    ctx.updateLoggers();
    test1();
}
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

LoggerConfig (org.apache.logging.log4j.core.config.LoggerConfig)63 Configuration (org.apache.logging.log4j.core.config.Configuration)38 LoggerContext (org.apache.logging.log4j.core.LoggerContext)32 Appender (org.apache.logging.log4j.core.Appender)11 Level (org.apache.logging.log4j.Level)9 Test (org.junit.Test)7 VisibleForTesting (com.google.common.annotations.VisibleForTesting)6 AppenderRef (org.apache.logging.log4j.core.config.AppenderRef)6 Logger (org.apache.logging.log4j.Logger)5 Filter (org.apache.logging.log4j.core.Filter)5 Configuration.getConfiguration (javax.security.auth.login.Configuration.getConfiguration)4 FileAppender (org.apache.logging.log4j.core.appender.FileAppender)4 ThresholdFilter (org.apache.logging.log4j.core.filter.ThresholdFilter)4 ConsoleAppender (org.apache.logging.log4j.core.appender.ConsoleAppender)3 PatternLayout (org.apache.logging.log4j.core.layout.PatternLayout)3 PropertyChangeListener (java.beans.PropertyChangeListener)2 File (java.io.File)2 Path (java.nio.file.Path)2 Map (java.util.Map)2 AppenderContext (org.apache.geode.internal.logging.log4j.AppenderContext)2