Search in sources :

Example 66 with Configuration

use of org.apache.logging.log4j.core.config.Configuration in project graylog2-server by Graylog2.

the class LoggersResource method getAppender.

private Appender getAppender(final String appenderName) {
    final LoggerContext loggerContext = (LoggerContext) LogManager.getContext(false);
    final Configuration configuration = loggerContext.getConfiguration();
    return configuration.getAppender(appenderName);
}
Also used : Configuration(org.apache.logging.log4j.core.config.Configuration) LoggerContext(org.apache.logging.log4j.core.LoggerContext)

Example 67 with Configuration

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

the class Log4jUtils method setRootLevel.

public static void setRootLevel(LogLevel logLevel) {
    LoggerContext coreContext = (LoggerContext) LogManager.getContext(false);
    Configuration configuration = coreContext.getConfiguration();
    for (LoggerConfig loggerConfig : configuration.getLoggers().values()) {
        setLevel(loggerConfig, logLevel);
    }
}
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 68 with Configuration

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

the class JabRefLogger method setLogLevelToDebugForJabRefClasses.

private static void setLogLevelToDebugForJabRefClasses() {
    LoggerContext ctx = (LoggerContext) LogManager.getContext(false);
    Configuration config = ctx.getConfiguration();
    LoggerConfig loggerConfig = config.getLoggerConfig("org.jabref");
    loggerConfig.setLevel(Level.DEBUG);
    ctx.updateLoggers();
}
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 69 with Configuration

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

the class Configurator method getOrCreateLoggerConfig.

public static LoggerConfig getOrCreateLoggerConfig(String name, boolean additive, boolean forceAdditivity) {
    LoggerContext context = (LoggerContext) LogManager.getContext(false);
    Configuration config = context.getConfiguration();
    LoggerConfig logConfig = config.getLoggerConfig(name);
    boolean update = false;
    if (!logConfig.getName().equals(name)) {
        List<AppenderRef> appenderRefs = logConfig.getAppenderRefs();
        Map<Property, Boolean> properties = logConfig.getProperties();
        Set<Property> props = properties == null ? null : properties.keySet();
        logConfig = LoggerConfig.createLogger(String.valueOf(additive), logConfig.getLevel(), name, String.valueOf(logConfig.isIncludeLocation()), appenderRefs == null ? null : appenderRefs.toArray(new AppenderRef[appenderRefs.size()]), props == null ? null : props.toArray(new Property[props.size()]), config, null);
        config.addLogger(name, logConfig);
        update = true;
    }
    if (forceAdditivity && logConfig.isAdditive() != additive) {
        logConfig.setAdditive(additive);
        update = true;
    }
    if (update) {
        context.updateLoggers();
    }
    return logConfig;
}
Also used : Configuration(org.apache.logging.log4j.core.config.Configuration) AppenderRef(org.apache.logging.log4j.core.config.AppenderRef) LoggerContext(org.apache.logging.log4j.core.LoggerContext) Property(org.apache.logging.log4j.core.config.Property) LoggerConfig(org.apache.logging.log4j.core.config.LoggerConfig)

Example 70 with Configuration

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

the class Configurator method getOrCreateLoggerConfig.

public static LoggerConfig getOrCreateLoggerConfig(String name) {
    LoggerContext context = (LoggerContext) LogManager.getContext(false);
    Configuration config = context.getConfiguration();
    LoggerConfig logConfig = config.getLoggerConfig(name);
    boolean update = false;
    if (!logConfig.getName().equals(name)) {
        List<AppenderRef> appenderRefs = logConfig.getAppenderRefs();
        Map<Property, Boolean> properties = logConfig.getProperties();
        Set<Property> props = properties == null ? null : properties.keySet();
        logConfig = LoggerConfig.createLogger(String.valueOf(logConfig.isAdditive()), logConfig.getLevel(), name, String.valueOf(logConfig.isIncludeLocation()), appenderRefs == null ? null : appenderRefs.toArray(new AppenderRef[appenderRefs.size()]), props == null ? null : props.toArray(new Property[props.size()]), config, null);
        config.addLogger(name, logConfig);
        update = true;
    }
    if (update) {
        context.updateLoggers();
    }
    return logConfig;
}
Also used : Configuration(org.apache.logging.log4j.core.config.Configuration) AppenderRef(org.apache.logging.log4j.core.config.AppenderRef) LoggerContext(org.apache.logging.log4j.core.LoggerContext) Property(org.apache.logging.log4j.core.config.Property) LoggerConfig(org.apache.logging.log4j.core.config.LoggerConfig)

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