Class KeyValuePairsJsonProvider

All Implemented Interfaces:
ContextAware, FieldNamesAware<LogstashFieldNames>, JsonProvider<ILoggingEvent>

public class KeyValuePairsJsonProvider extends AbstractFieldJsonProvider<ILoggingEvent> implements FieldNamesAware<LogstashFieldNames>
Includes key value pairs added from slf4j's fluent api in the output according to includeKeyNames and excludeKeyNames.

There are three valid combinations of includeKeyNames and excludeKeyNames:

  1. When includeKeyNames and excludeKeyNames are both empty, then all entries will be included.
  2. When includeKeyNames is not empty and excludeKeyNames is empty, then only those entries with key names in includeKeyNames will be included.
  3. When includeKeyNames is empty and excludeKeyNames is not empty, then all entries except those with key names in excludeKeyNames will be included.

It is a configuration error for both includeKeyNames and excludeKeyNames to be not empty.

By default, for each key value pair, the key is output as the field name. This can be changed by specifying an explicit field name to use for a ke via addKeyFieldName(String)

If the fieldName is set, then the pairs will be written to that field as a subobject. Otherwise, the pairs are written inline.

  • Constructor Details

    • KeyValuePairsJsonProvider

      public KeyValuePairsJsonProvider()
  • Method Details

    • start

      public void start()
      Description copied from interface: JsonProvider
      Start the provider after all configuration properties are set.
      Specified by:
      start in interface JsonProvider<ILoggingEvent>
      Overrides:
      start in class AbstractJsonProvider<ILoggingEvent>
    • writeTo

      public void writeTo(JsonGenerator generator, ILoggingEvent event) throws IOException
      Description copied from interface: JsonProvider
      Writes information about the event, to the given generator.

      When called, the generator is assumed to be within a JSON object context (i.e. this provider should write fields and their values to the generator). Upon return, the generator should be within the same JSON object context.

      Specified by:
      writeTo in interface JsonProvider<ILoggingEvent>
      Parameters:
      generator - the JsonGenerator to produce JSON content
      event - the event to convert into JSON
      Throws:
      IOException - if an I/O error occurs
    • setFieldNames

      public void setFieldNames(LogstashFieldNames fieldNames)
      Specified by:
      setFieldNames in interface FieldNamesAware<LogstashFieldNames>
    • getIncludeKeyNames

      public List<String> getIncludeKeyNames()
    • addIncludeKeyName

      public void addIncludeKeyName(String includedKeyName)
    • setIncludeKeyNames

      public void setIncludeKeyNames(List<String> includeKeyNames)
    • getExcludeKeyNames

      public List<String> getExcludeKeyNames()
    • addExcludeKeyName

      public void addExcludeKeyName(String excludedKeyName)
    • setExcludeKeyNames

      public void setExcludeKeyNames(List<String> excludeKeyNames)
    • getKeyFieldNames

      public Map<String,String> getKeyFieldNames()
    • addKeyFieldName

      public void addKeyFieldName(String keyFieldName)
      Adds the given keyFieldName entry in the form keyName=fieldName to use an alternative field name for an KeyValuePair key.
      Parameters:
      keyFieldName - a string in the form kvpKeyName=fieldName that identifies what field name to use for a specific KeyValuePair key.