Search in sources :

Example 46 with LoggerConfig

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

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

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

the class Configurator method hasLoggerFilter.

public static boolean hasLoggerFilter(final Configuration config) {
    for (LoggerConfig loggerConfig : config.getLoggers().values()) {
        boolean isRoot = loggerConfig.getName().equals("");
        boolean isGemFire = loggerConfig.getName().startsWith(LogService.BASE_LOGGER_NAME);
        boolean hasFilter = loggerConfig.hasFilter();
        boolean isGemFireVerboseFilter = hasFilter && (LogService.GEODE_VERBOSE_FILTER.equals(loggerConfig.getFilter().toString()) || LogService.GEMFIRE_VERBOSE_FILTER.equals(loggerConfig.getFilter().toString()));
        if (isRoot || isGemFire) {
            // check for Logger Filter
            if (hasFilter && !isGemFireVerboseFilter) {
                return true;
            }
        }
    }
    return false;
}
Also used : LoggerConfig(org.apache.logging.log4j.core.config.LoggerConfig)

Example 49 with LoggerConfig

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

Example 50 with LoggerConfig

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

the class Configurator method hasAppenderRefFilter.

public static boolean hasAppenderRefFilter(final Configuration config) {
    for (LoggerConfig loggerConfig : config.getLoggers().values()) {
        boolean isRoot = loggerConfig.getName().equals("");
        boolean isGemFire = loggerConfig.getName().startsWith(LogService.BASE_LOGGER_NAME);
        if (isRoot || isGemFire) {
            // check for AppenderRef Filter
            for (AppenderRef appenderRef : loggerConfig.getAppenderRefs()) {
                if (appenderRef.getFilter() != null) {
                    return true;
                }
            }
        }
    }
    return false;
}
Also used : AppenderRef(org.apache.logging.log4j.core.config.AppenderRef) 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