use of org.apache.logging.log4j.plugins.PluginFactory in project logging-log4j2 by apache.
the class StructuredDataFilter method createFilter.
/**
* Creates the StructuredDataFilter.
* @param pairs Key and value pairs.
* @param operator The operator to perform. If not "or" the operation will be an "and".
* @param onMatch The action to perform on a match.
* @param onMismatch The action to perform on a mismatch.
* @return The StructuredDataFilter.
*/
// TODO Consider refactoring to use AbstractFilter.AbstractFilterBuilder
@PluginFactory
public static StructuredDataFilter createFilter(@PluginElement final KeyValuePair[] pairs, @PluginAttribute final String operator, @PluginAttribute final Result onMatch, @PluginAttribute final Result onMismatch) {
if (pairs == null || pairs.length == 0) {
LOGGER.error("keys and values must be specified for the StructuredDataFilter");
return null;
}
final Map<String, List<String>> map = new HashMap<>();
for (final KeyValuePair pair : pairs) {
final String key = pair.getKey();
if (key == null) {
LOGGER.error("A null key is not valid in MapFilter");
continue;
}
final String value = pair.getValue();
if (value == null) {
LOGGER.error("A null value for key " + key + " is not allowed in MapFilter");
continue;
}
List<String> list = map.get(pair.getKey());
if (list != null) {
list.add(value);
} else {
list = new ArrayList<>();
list.add(value);
map.put(pair.getKey(), list);
}
}
if (map.isEmpty()) {
LOGGER.error("StructuredDataFilter is not configured with any valid key value pairs");
return null;
}
final boolean isAnd = operator == null || !operator.equalsIgnoreCase("or");
return new StructuredDataFilter(map, isAnd, onMatch, onMismatch);
}
use of org.apache.logging.log4j.plugins.PluginFactory in project logging-log4j2 by apache.
the class ThresholdFilter method createFilter.
/**
* Creates a ThresholdFilter.
* @param level The log Level.
* @param match The action to take on a match.
* @param mismatch The action to take on a mismatch.
* @return The created ThresholdFilter.
*/
// TODO Consider refactoring to use AbstractFilter.AbstractFilterBuilder
@PluginFactory
public static ThresholdFilter createFilter(@PluginAttribute final Level level, @PluginAttribute("onMatch") final Result match, @PluginAttribute("onMismatch") final Result mismatch) {
final Level actualLevel = level == null ? Level.ERROR : level;
final Result onMatch = match == null ? Result.NEUTRAL : match;
final Result onMismatch = mismatch == null ? Result.DENY : mismatch;
return new ThresholdFilter(actualLevel, onMatch, onMismatch);
}
use of org.apache.logging.log4j.plugins.PluginFactory in project logging-log4j2 by apache.
the class LevelRangeFilter method createFilter.
/**
* Creates a ThresholdFilter.
*
* @param minLevel
* The minimum log Level.
* @param maxLevel
* The maximum log Level.
* @param match
* The action to take on a match.
* @param mismatch
* The action to take on a mismatch.
* @return The created ThresholdFilter.
*/
// TODO Consider refactoring to use AbstractFilter.AbstractFilterBuilder
@PluginFactory
public static LevelRangeFilter createFilter(// @formatter:off
@PluginAttribute final Level minLevel, @PluginAttribute final Level maxLevel, @PluginAttribute final Result match, @PluginAttribute final Result mismatch) {
// @formatter:on
final Level actualMinLevel = minLevel == null ? Level.ERROR : minLevel;
final Level actualMaxLevel = maxLevel == null ? Level.ERROR : maxLevel;
final Result onMatch = match == null ? Result.NEUTRAL : match;
final Result onMismatch = mismatch == null ? Result.DENY : mismatch;
return new LevelRangeFilter(actualMinLevel, actualMaxLevel, onMatch, onMismatch);
}
use of org.apache.logging.log4j.plugins.PluginFactory in project logging-log4j2 by apache.
the class ThreadContextMapFilter method createFilter.
// TODO Consider refactoring to use AbstractFilter.AbstractFilterBuilder
@PluginFactory
public static ThreadContextMapFilter createFilter(@PluginElement final KeyValuePair[] pairs, @PluginAttribute final String operator, @PluginAttribute final Result onMatch, @PluginAttribute final Result onMismatch) {
if (pairs == null || pairs.length == 0) {
LOGGER.error("key and value pairs must be specified for the ThreadContextMapFilter");
return null;
}
final Map<String, List<String>> map = new HashMap<>();
for (final KeyValuePair pair : pairs) {
final String key = pair.getKey();
if (key == null) {
LOGGER.error("A null key is not valid in MapFilter");
continue;
}
final String value = pair.getValue();
if (value == null) {
LOGGER.error("A null value for key " + key + " is not allowed in MapFilter");
continue;
}
List<String> list = map.get(pair.getKey());
if (list != null) {
list.add(value);
} else {
list = new ArrayList<>();
list.add(value);
map.put(pair.getKey(), list);
}
}
if (map.isEmpty()) {
LOGGER.error("ThreadContextMapFilter is not configured with any valid key value pairs");
return null;
}
final boolean isAnd = operator == null || !operator.equalsIgnoreCase("or");
return new ThreadContextMapFilter(map, isAnd, onMatch, onMismatch);
}
use of org.apache.logging.log4j.plugins.PluginFactory in project logging-log4j2 by apache.
the class CronTriggeringPolicy method createPolicy.
/**
* Creates a ScheduledTriggeringPolicy.
*
* @param configuration
* the Configuration.
* @param evaluateOnStartup
* check if the file should be rolled over immediately.
* @param schedule
* the cron expression.
* @return a ScheduledTriggeringPolicy.
*/
@PluginFactory
public static CronTriggeringPolicy createPolicy(@PluginConfiguration final Configuration configuration, @PluginAttribute final String evaluateOnStartup, @PluginAttribute final String schedule) {
CronExpression cronExpression;
final boolean checkOnStartup = Boolean.parseBoolean(evaluateOnStartup);
if (schedule == null) {
LOGGER.info("No schedule specified, defaulting to Daily");
cronExpression = getSchedule(defaultSchedule);
} else {
cronExpression = getSchedule(schedule);
if (cronExpression == null) {
LOGGER.error("Invalid expression specified. Defaulting to Daily");
cronExpression = getSchedule(defaultSchedule);
}
}
return new CronTriggeringPolicy(cronExpression, checkOnStartup, configuration);
}
Aggregations