Search in sources :

Example 56 with LoggerContext

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

the class XmlConfigurationPropsTest method testNoProps.

@Test
public void testNoProps() {
    System.setProperty(ConfigurationFactory.CONFIGURATION_FILE_PROPERTY, CONFIG);
    final LoggerContext ctx = LoggerContext.getContext();
    ctx.reconfigure();
    final Configuration config = ctx.getConfiguration();
    assertTrue("Configuration is not an XmlConfiguration", config instanceof XmlConfiguration);
}
Also used : Configuration(org.apache.logging.log4j.core.config.Configuration) LoggerContext(org.apache.logging.log4j.core.LoggerContext) Test(org.junit.Test)

Example 57 with LoggerContext

use of org.apache.logging.log4j.core.LoggerContext 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)

Example 58 with LoggerContext

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

the class Configurator method setLevel.

public static void setLevel(String name, Level level) {
    LoggerContext context = (LoggerContext) LogManager.getContext(false);
    LoggerConfig logConfig = getLoggerConfig(name);
    logConfig.setLevel(level);
    context.updateLoggers();
    if (level.isLessSpecificThan(Level.DEBUG)) {
        LogService.configureFastLoggerDelegating();
    }
}
Also used : LoggerContext(org.apache.logging.log4j.core.LoggerContext) LoggerConfig(org.apache.logging.log4j.core.config.LoggerConfig)

Example 59 with LoggerContext

use of org.apache.logging.log4j.core.LoggerContext in project spring-boot by spring-projects.

the class Log4J2LoggingSystem method loadConfiguration.

protected void loadConfiguration(String location, LogFile logFile) {
    Assert.notNull(location, "Location must not be null");
    try {
        LoggerContext ctx = getLoggerContext();
        URL url = ResourceUtils.getURL(location);
        ConfigurationSource source = getConfigurationSource(url);
        ctx.start(ConfigurationFactory.getInstance().getConfiguration(ctx, source));
    } catch (Exception ex) {
        throw new IllegalStateException("Could not initialize Log4J2 logging from " + location, ex);
    }
}
Also used : ConfigurationSource(org.apache.logging.log4j.core.config.ConfigurationSource) LoggerContext(org.apache.logging.log4j.core.LoggerContext) URL(java.net.URL) IOException(java.io.IOException)

Example 60 with LoggerContext

use of org.apache.logging.log4j.core.LoggerContext in project spring-boot by spring-projects.

the class Log4J2LoggingSystem method cleanUp.

@Override
public void cleanUp() {
    super.cleanUp();
    LoggerContext loggerContext = getLoggerContext();
    markAsUninitialized(loggerContext);
    loggerContext.getConfiguration().removeFilter(FILTER);
}
Also used : LoggerContext(org.apache.logging.log4j.core.LoggerContext)

Aggregations

LoggerContext (org.apache.logging.log4j.core.LoggerContext)163 Configuration (org.apache.logging.log4j.core.config.Configuration)57 LoggerConfig (org.apache.logging.log4j.core.config.LoggerConfig)36 Test (org.junit.Test)33 Appender (org.apache.logging.log4j.core.Appender)18 File (java.io.File)12 IOException (java.io.IOException)12 Logger (org.apache.logging.log4j.Logger)11 BeforeClass (org.junit.BeforeClass)11 Map (java.util.Map)10 Level (org.apache.logging.log4j.Level)8 LogEvent (org.apache.logging.log4j.core.LogEvent)8 Log4jLogEvent (org.apache.logging.log4j.core.impl.Log4jLogEvent)7 PatternLayout (org.apache.logging.log4j.core.layout.PatternLayout)7 SimpleMessage (org.apache.logging.log4j.message.SimpleMessage)7 Logger (org.apache.logging.log4j.core.Logger)6 AbstractConfiguration (org.apache.logging.log4j.core.config.AbstractConfiguration)5 FileAppender (org.apache.logging.log4j.core.appender.FileAppender)4 RoutingAppender (org.apache.logging.log4j.core.appender.routing.RoutingAppender)4 BuiltConfiguration (org.apache.logging.log4j.core.config.builder.impl.BuiltConfiguration)4