Search in sources :

Example 6 with AppenderRef

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

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

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

Example 9 with AppenderRef

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

the class AsyncLoggerConfig method createLogger.

/**
     * Factory method to create a LoggerConfig.
     *
     * @param additivity True if additive, false otherwise.
     * @param levelName The Level to be associated with the Logger.
     * @param loggerName The name of the Logger.
     * @param includeLocation "true" if location should be passed downstream
     * @param refs An array of Appender names.
     * @param properties Properties to pass to the Logger.
     * @param config The Configuration.
     * @param filter A Filter.
     * @return A new LoggerConfig.
     */
@PluginFactory
public static LoggerConfig createLogger(@PluginAttribute("additivity") final String additivity, @PluginAttribute("level") final String levelName, @PluginAttribute("name") final String loggerName, @PluginAttribute("includeLocation") final String includeLocation, @PluginElement("AppenderRef") final AppenderRef[] refs, @PluginElement("Properties") final Property[] properties, @PluginConfiguration final Configuration config, @PluginElement("Filter") final Filter filter) {
    if (loggerName == null) {
        LOGGER.error("Loggers cannot be configured without a name");
        return null;
    }
    final List<AppenderRef> appenderRefs = Arrays.asList(refs);
    Level level;
    try {
        level = Level.toLevel(levelName, Level.ERROR);
    } catch (final Exception ex) {
        LOGGER.error("Invalid Log level specified: {}. Defaulting to Error", levelName);
        level = Level.ERROR;
    }
    final String name = loggerName.equals(LoggerConfig.ROOT) ? Strings.EMPTY : loggerName;
    final boolean additive = Booleans.parseBoolean(additivity, true);
    return new AsyncLoggerConfig(name, appenderRefs, filter, level, additive, properties, config, includeLocation(includeLocation));
}
Also used : Level(org.apache.logging.log4j.Level) AppenderRef(org.apache.logging.log4j.core.config.AppenderRef) PluginFactory(org.apache.logging.log4j.core.config.plugins.PluginFactory)

Aggregations

AppenderRef (org.apache.logging.log4j.core.config.AppenderRef)9 LoggerConfig (org.apache.logging.log4j.core.config.LoggerConfig)6 LoggerContext (org.apache.logging.log4j.core.LoggerContext)5 Configuration (org.apache.logging.log4j.core.config.Configuration)4 Appender (org.apache.logging.log4j.core.Appender)3 ConsoleAppender (org.apache.logging.log4j.core.appender.ConsoleAppender)2 AppenderControl (org.apache.logging.log4j.core.config.AppenderControl)2 Property (org.apache.logging.log4j.core.config.Property)2 PatternLayout (org.apache.logging.log4j.core.layout.PatternLayout)2 ArrayList (java.util.ArrayList)1 IgniteLogger (org.apache.ignite.IgniteLogger)1 Level (org.apache.logging.log4j.Level)1 Filter (org.apache.logging.log4j.core.Filter)1 Layout (org.apache.logging.log4j.core.Layout)1 Logger (org.apache.logging.log4j.core.Logger)1 AbstractAppender (org.apache.logging.log4j.core.appender.AbstractAppender)1 FileAppender (org.apache.logging.log4j.core.appender.FileAppender)1 AbstractConfiguration (org.apache.logging.log4j.core.config.AbstractConfiguration)1 ConfigurationException (org.apache.logging.log4j.core.config.ConfigurationException)1 PluginFactory (org.apache.logging.log4j.core.config.plugins.PluginFactory)1