Class KeyValuePairsJsonProvider
java.lang.Object
ch.qos.logback.core.spi.ContextAwareBase
net.logstash.logback.composite.AbstractJsonProvider<Event>
net.logstash.logback.composite.AbstractFieldJsonProvider<ILoggingEvent>
net.logstash.logback.composite.loggingevent.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
:
- When
includeKeyNames
andexcludeKeyNames
are both empty, then all entries will be included. - When
includeKeyNames
is not empty andexcludeKeyNames
is empty, then only those entries with key names inincludeKeyNames
will be included. - When
includeKeyNames
is empty andexcludeKeyNames
is not empty, then all entries except those with key names inexcludeKeyNames
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.
-
Field Summary
Fields inherited from class ch.qos.logback.core.spi.ContextAwareBase
context
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoid
addExcludeKeyName
(String excludedKeyName) void
addIncludeKeyName
(String includedKeyName) void
addKeyFieldName
(String keyFieldName) Adds the given keyFieldName entry in the form keyName=fieldName to use an alternative field name for an KeyValuePair key.void
setExcludeKeyNames
(List<String> excludeKeyNames) void
setFieldNames
(LogstashFieldNames fieldNames) void
setIncludeKeyNames
(List<String> includeKeyNames) void
start()
Start the provider after all configuration properties are set.void
writeTo
(JsonGenerator generator, ILoggingEvent event) Writes information about the event, to the given generator.Methods inherited from class net.logstash.logback.composite.AbstractFieldJsonProvider
getFieldName, setFieldName
Methods inherited from class net.logstash.logback.composite.AbstractJsonProvider
assertIsStarted, isStarted, prepareForDeferredProcessing, stop
Methods inherited from class ch.qos.logback.core.spi.ContextAwareBase
addError, addError, addInfo, addInfo, addStatus, addWarn, addWarn, getContext, getDeclaredOrigin, getStatusManager, setContext
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface ch.qos.logback.core.spi.ContextAware
addError, addError, addInfo, addInfo, addStatus, addWarn, addWarn, getContext, setContext
-
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 interfaceJsonProvider<ILoggingEvent>
- Overrides:
start
in classAbstractJsonProvider<ILoggingEvent>
-
writeTo
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 interfaceJsonProvider<ILoggingEvent>
- Parameters:
generator
- theJsonGenerator
to produce JSON contentevent
- the event to convert into JSON- Throws:
IOException
- if an I/O error occurs
-
setFieldNames
- Specified by:
setFieldNames
in interfaceFieldNamesAware<LogstashFieldNames>
-
getIncludeKeyNames
-
addIncludeKeyName
-
setIncludeKeyNames
-
getExcludeKeyNames
-
addExcludeKeyName
-
setExcludeKeyNames
-
getKeyFieldNames
-
addKeyFieldName
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.
-