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;
}
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;
}
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;
}
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));
}
Aggregations