public class MdcJsonProvider extends AbstractFieldJsonProvider<ILoggingEvent> implements FieldNamesAware<LogstashFieldNames>
MDC
properties in the JSON output according to
includeMdcKeyNames
and excludeMdcKeyNames
.
There are three valid combinations of includeMdcKeyNames
and excludeMdcKeyNames
:
includeMdcKeyNames
and excludeMdcKeyNames
are both empty, then all entries will be included.includeMdcKeyNames
is not empty and
excludeMdcKeyNames
is empty, then only those entries
with key names in includeMdcKeyNames
will be included.includeMdcKeyNames
is empty and
excludeMdcKeyNames
is not empty, then all entries except those
with key names in excludeMdcKeyNames
will be included.It is a configuration error for both includeMdcKeyNames
and excludeMdcKeyNames
to be not empty.
By default, for each entry in the MDC, the MDC key is output as the field name.
This can be changed by specifying an explicit field name to use for an MDC key
via addMdcKeyFieldName(String)
If the fieldName is set, then the properties will be written to that field as a subobject. Otherwise, the properties are written inline.
context
Constructor and Description |
---|
MdcJsonProvider() |
Modifier and Type | Method and Description |
---|---|
void |
addExcludeMdcKeyName(String excludedMdcKeyName) |
void |
addIncludeMdcKeyName(String includedMdcKeyName) |
void |
addMdcKeyFieldName(String mdcKeyFieldName)
Adds the given mdcKeyFieldName entry in the form mdcKeyName=fieldName
to use an alternative field name for an MDC key.
|
List<String> |
getExcludeMdcKeyNames() |
List<String> |
getIncludeMdcKeyNames() |
Map<String,String> |
getMdcKeyFieldNames() |
void |
setExcludeMdcKeyNames(List<String> excludeMdcKeyNames) |
void |
setFieldNames(LogstashFieldNames fieldNames) |
void |
setIncludeMdcKeyNames(List<String> includeMdcKeyNames) |
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.
|
getFieldName, setFieldName
isStarted, prepareForDeferredProcessing, stop
addError, addError, addInfo, addInfo, addStatus, addWarn, addWarn, getContext, getDeclaredOrigin, getStatusManager, setContext
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
addError, addError, addInfo, addInfo, addStatus, addWarn, addWarn, getContext, setContext
public void start()
JsonProvider
start
in interface JsonProvider<ILoggingEvent>
start
in class AbstractJsonProvider<ILoggingEvent>
public void writeTo(JsonGenerator generator, ILoggingEvent event) throws IOException
JsonProvider
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.
writeTo
in interface JsonProvider<ILoggingEvent>
generator
- the JsonGenerator
to produce JSON contentevent
- the event to convert into JSONIOException
- if an I/O error occurspublic void setFieldNames(LogstashFieldNames fieldNames)
setFieldNames
in interface FieldNamesAware<LogstashFieldNames>
public void addIncludeMdcKeyName(String includedMdcKeyName)
public void addExcludeMdcKeyName(String excludedMdcKeyName)
public void addMdcKeyFieldName(String mdcKeyFieldName)
mdcKeyFieldName
- a string in the form mdcKeyName=fieldName that identifies what field name to use for a specific MDC key.Copyright © 2013–2021. All rights reserved.