Class MdcJsonProvider
- All Implemented Interfaces:
ContextAware,FieldNamesAware<LogstashFieldNames>,JsonProvider<ILoggingEvent>
MDC properties in the JSON output according to
includeMdcKeyNames and excludeMdcKeyNames.
There are three valid combinations of includeMdcKeyNames
and excludeMdcKeyNames:
- When
includeMdcKeyNamesandexcludeMdcKeyNamesare both empty, then all entries will be included. - When
includeMdcKeyNamesis not empty andexcludeMdcKeyNamesis empty, then only those entries with key names inincludeMdcKeyNameswill be included. - When
includeMdcKeyNamesis empty andexcludeMdcKeyNamesis not empty, then all entries except those with key names inexcludeMdcKeyNameswill 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.
The output of the MDC entry values can be manipulated by the provided
mdcEntryWriters. By default, all MDC entry values are written as texts.
-
Field Summary
FieldsModifier and TypeFieldDescriptionSeeMdcJsonProvider.SeeMdcJsonProvider.protected final List<MdcEntryWriter> SeeMdcJsonProvider.Fields inherited from class ch.qos.logback.core.spi.ContextAwareBase
context -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidaddExcludeMdcKeyName(String excludedMdcKeyName) voidaddIncludeMdcKeyName(String includedMdcKeyName) voidaddMdcEntryWriter(MdcEntryWriter mdcEntryWriter) voidaddMdcKeyFieldName(String mdcKeyFieldName) Adds the given mdcKeyFieldName entry in the form mdcKeyName=fieldName to use an alternative field name for an MDC key.voidsetExcludeMdcKeyNames(List<String> excludeMdcKeyNames) voidsetFieldNames(LogstashFieldNames fieldNames) voidsetIncludeMdcKeyNames(List<String> includeMdcKeyNames) voidstart()Start the provider after all configuration properties are set.voidwriteTo(JsonGenerator generator, ILoggingEvent event) Writes information about the event, to the given generator.Methods inherited from class net.logstash.logback.composite.AbstractFieldJsonProvider
getFieldName, setFieldNameMethods inherited from class net.logstash.logback.composite.AbstractJsonProvider
assertIsStarted, isStarted, prepareForDeferredProcessing, stopMethods inherited from class ch.qos.logback.core.spi.ContextAwareBase
addError, addError, addInfo, addInfo, addStatus, addWarn, addWarn, getContext, getDeclaredOrigin, getStatusManager, setContextMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface ch.qos.logback.core.spi.ContextAware
addError, addError, addInfo, addInfo, addStatus, addWarn, addWarn, getContext, setContext
-
Field Details
-
includeMdcKeyNames
SeeMdcJsonProvider. -
excludeMdcKeyNames
SeeMdcJsonProvider. -
mdcKeyFieldNames
-
mdcEntryWriters
SeeMdcJsonProvider.
-
-
Constructor Details
-
MdcJsonProvider
public MdcJsonProvider()
-
-
Method Details
-
start
public void start()Description copied from interface:JsonProviderStart the provider after all configuration properties are set.- Specified by:
startin interfaceJsonProvider<ILoggingEvent>- Overrides:
startin classAbstractJsonProvider<ILoggingEvent>
-
writeTo
Description copied from interface:JsonProviderWrites 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:
writeToin interfaceJsonProvider<ILoggingEvent>- Parameters:
generator- theJsonGeneratorto produce JSON contentevent- the event to convert into JSON- Throws:
IOException- if an I/O error occurs
-
setFieldNames
- Specified by:
setFieldNamesin interfaceFieldNamesAware<LogstashFieldNames>
-
getIncludeMdcKeyNames
-
addIncludeMdcKeyName
-
setIncludeMdcKeyNames
-
getExcludeMdcKeyNames
-
addExcludeMdcKeyName
-
setExcludeMdcKeyNames
-
getMdcKeyFieldNames
-
getMdcEntryWriters
-
addMdcEntryWriter
-
addMdcKeyFieldName
Adds the given mdcKeyFieldName entry in the form mdcKeyName=fieldName to use an alternative field name for an MDC key.- Parameters:
mdcKeyFieldName- a string in the form mdcKeyName=fieldName that identifies what field name to use for a specific MDC key.
-