net.logstash.logback.encoder.org.apache.commons.lang.StringUtils Java Examples

The following examples show how to use net.logstash.logback.encoder.org.apache.commons.lang.StringUtils. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: JsonMessageBuilderProvider.java    From godaddy-logger with MIT License 5 votes vote down vote up
private Map<String, Object> getUnnamedContext(Map<String, Object> logContext) {
    Map<String, Object> unnamed = new HashMap<>();

    logContext.keySet()
              .stream()
              .filter(key -> key.equals(StringUtils.EMPTY))
              .forEach(key -> unnamed.put(key, logContext.get(key)));

    return unnamed;
}
 
Example #2
Source File: JsonMessageBuilderProvider.java    From godaddy-logger with MIT License 5 votes vote down vote up
private Map<String, Object> appendNamedContext(Map<String, Object> logContext, Map<String, List<String>> keyNames, Map<String, Integer> keyCollisionIdentifier) {
    Map<String, Object> named = new HashMap<>();

    logContext.keySet()
              .stream()
              .filter(key -> !key.equals(StringUtils.EMPTY))
              .forEach(key -> {
                  String name = key;
                  /**
                   * _unnamed_values is a reserved key for values with no key.
                   * If a named key with the value of _unnamed_values is received, a counter value will be appended to the key name.
                   */
                  if (keyNames.get(key).size() > 1 || key.equals(CommonKeys.UNNAMED_VALUES_KEY)) {
                      if (!keyCollisionIdentifier.containsKey(key)) {
                          keyCollisionIdentifier.put(key, 1);
                      }

                      Integer identity = keyCollisionIdentifier.get(key);

                      name = identity == 1 && !key.equals(CommonKeys.UNNAMED_VALUES_KEY) ? name : (name += identity);

                      keyCollisionIdentifier.put(key, ++identity);
                  }

                  named.put(name, logContext.get(key));
              });

    return named;
}