org.apache.logging.log4j.core.util.KeyValuePair#getValue ( )源码实例Demo

下面列出了org.apache.logging.log4j.core.util.KeyValuePair#getValue ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: ecs-logging-java   文件: EcsLayout.java
private void serializeAdditionalFieldsAndMDC(LogEvent event, StringBuilder builder) {
    final int length = additionalFields.length;
    if (!event.getContextData().isEmpty() || length > 0) {
        if (length > 0) {
            final StrSubstitutor strSubstitutor = getConfiguration().getStrSubstitutor();
            for (int i = 0; i < length; i++) {
                KeyValuePair additionalField = additionalFields[i];
                PatternFormatter[] formatters = fieldValuePatternFormatter[i];
                CharSequence value = null;
                if (formatters != null) {
                    StringBuilder buffer = EcsJsonSerializer.getMessageStringBuilder();
                    formatPattern(event, formatters, buffer);
                    if (buffer.length() > 0) {
                        value = buffer;
                    }
                } else if (valueNeedsLookup(additionalField.getValue())) {
                    StringBuilder lookupValue = EcsJsonSerializer.getMessageStringBuilder();
                    lookupValue.append(additionalField.getValue());
                    if (strSubstitutor.replaceIn(event, lookupValue)) {
                        value = lookupValue;
                    }
                } else {
                    value = additionalField.getValue();
                }

                if (value != null) {
                    builder.append('\"');
                    JsonUtils.quoteAsString(additionalField.getKey(), builder);
                    builder.append("\":\"");
                    JsonUtils.quoteAsString(EcsJsonSerializer.toNullSafeString(value), builder);
                    builder.append("\",");
                }
            }
        }
        event.getContextData().forEach(WRITE_MDC, builder);
    }
}
 
源代码2 项目: logging-log4j2   文件: MapRewritePolicy.java
/**
 * The factory method to create the MapRewritePolicy.
 * @param mode The string representation of the Mode.
 * @param pairs key/value pairs for the new Map keys and values.
 * @return The MapRewritePolicy.
 */
@PluginFactory
public static MapRewritePolicy createPolicy(
        @PluginAttribute final String mode,
        @PluginElement("KeyValuePair") final KeyValuePair[] pairs) {
    Mode op = mode == null ? op = Mode.Add : Mode.valueOf(mode);
    if (pairs == null || pairs.length == 0) {
        LOGGER.error("keys and values must be specified for the MapRewritePolicy");
        return null;
    }
    final Map<String, Object> 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 MapRewritePolicy");
            continue;
        }
        final String value = pair.getValue();
        if (value == null) {
            LOGGER.error("A null value for key " + key + " is not allowed in MapRewritePolicy");
            continue;
        }
        map.put(pair.getKey(), pair.getValue());
    }
    if (map.isEmpty()) {
        LOGGER.error("MapRewritePolicy is not configured with any valid key value pairs");
        return null;
    }
    return new MapRewritePolicy(map, op);
}
 
源代码3 项目: logging-log4j2   文件: ThreadContextMapFilter.java
@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);
}
 
源代码4 项目: logging-log4j2   文件: MapFilter.java
@PluginFactory
public static MapFilter 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 MapFilter");
        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("MapFilter is not configured with any valid key value pairs");
        return null;
    }
    final boolean isAnd = operator == null || !operator.equalsIgnoreCase("or");
    return new MapFilter(map, isAnd, onMatch, onMismatch);
}
 
源代码5 项目: logging-log4j2   文件: StructuredDataFilter.java
/**
 * 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);
}
 
源代码6 项目: curiostack   文件: AbstractJacksonLayout.java
ResolvableKeyValuePair(final KeyValuePair pair) {
  this.key = pair.getKey();
  this.value = pair.getValue();
  this.valueNeedsLookup = AbstractJacksonLayout.valueNeedsLookup(this.value);
}
 
源代码7 项目: logging-log4j2   文件: AbstractJacksonLayout.java
ResolvableKeyValuePair(final KeyValuePair pair) {
    this.key = pair.getKey();
    this.value = pair.getValue();
    this.valueNeedsLookup = AbstractJacksonLayout.valueNeedsLookup(this.value);
}
 
源代码8 项目: logging-log4j2   文件: AbstractJacksonLayout.java
ResolvableKeyValuePair(final KeyValuePair pair) {
    this.key = pair.getKey();
    this.value = pair.getValue();
    this.valueNeedsLookup = AbstractJacksonLayout.valueNeedsLookup(this.value);
}