Package net.logstash.logback
Class LogstashFormatter
- All Implemented Interfaces:
ContextAware
,LifeCycle
A
LoggingEventCompositeJsonFormatter
that contains a common
pre-defined set of JsonProvider
s.
The included providers are configured via properties on this
formatter, rather than configuring the providers directly.
This leads to a somewhat simpler configuration definitions.
You cannot remove any of the pre-defined providers, but
you can add additional providers via addProvider(JsonProvider)
.
If you would like full control over the providers, you
should instead use LoggingEventCompositeJsonFormatter
directly.-
Field Summary
Modifier and TypeFieldDescriptionprotected LogstashFieldNames
The field names to use when writing the standard event fieldsFields inherited from class ch.qos.logback.core.spi.ContextAwareBase
context
-
Constructor Summary
ConstructorDescriptionLogstashFormatter
(ContextAware declaredOrigin) LogstashFormatter
(ContextAware declaredOrigin, boolean includeCallerData) LogstashFormatter
(ContextAware declaredOrigin, boolean includeCallerData, JsonNode customFields) -
Method Summary
Modifier and TypeMethodDescriptionvoid
addExcludeMdcKeyName
(String excludedMdcKeyName) void
addIncludeMdcKeyName
(String includedMdcKeyName) void
addMdcKeyFieldName
(String mdcKeyFieldName) void
addProvider
(JsonProvider<ILoggingEvent> provider) protected void
Write the message as a JSON array by splitting the message text using the specified regex.int
boolean
boolean
boolean
boolean
boolean
boolean
boolean
void
setCustomFields
(JsonNode customFields) void
setCustomFieldsFromString
(String customFields) void
setExcludeMdcKeyNames
(List<String> excludeMdcKeyNames) void
setFieldNames
(LogstashFieldNames fieldNames) void
setIncludeCallerData
(boolean includeCallerData) void
setIncludeContext
(boolean includeContext) void
setIncludeMdc
(boolean includeMdc) void
setIncludeMdcKeyNames
(List<String> includeMdcKeyNames) void
setIncludeNonStructuredArguments
(boolean includeNonStructuredArguments) void
setIncludeStructuredArguments
(boolean includeStructuredArguments) void
setIncludeTags
(boolean includeTags) void
setMessageSplitRegex
(String messageSplitRegex) Write the message as a JSON array by splitting the message text using the specified regex.void
setNonStructuredArgumentsFieldPrefix
(String nonStructuredArgumentsFieldPrefix) void
setProviders
(JsonProviders<ILoggingEvent> jsonProviders) void
setShortenedLoggerNameLength
(int length) void
setThrowableConverter
(ThrowableHandlingConverter throwableConverter) void
setTimestampPattern
(String pattern) void
setTimeZone
(String timeZoneId) void
setVersion
(String version) void
setWriteVersionAsInteger
(boolean writeVersionAsInteger) void
start()
Methods inherited from class net.logstash.logback.composite.AbstractCompositeJsonFormatter
getEncoding, getJsonFactory, getJsonFactoryDecorator, getJsonGeneratorDecorator, isFindAndRegisterJacksonModules, isStarted, prepareForDeferredProcessing, setEncoding, setFindAndRegisterJacksonModules, setJsonFactoryDecorator, setJsonGeneratorDecorator, stop, writeEvent, writeEventToGenerator
Methods inherited from class ch.qos.logback.core.spi.ContextAwareBase
addError, addError, addInfo, addInfo, addStatus, addWarn, addWarn, getContext, getDeclaredOrigin, getStatusManager, setContext
-
Field Details
-
fieldNames
The field names to use when writing the standard event fields
-
-
Constructor Details
-
LogstashFormatter
-
LogstashFormatter
-
LogstashFormatter
public LogstashFormatter(ContextAware declaredOrigin, boolean includeCallerData, JsonNode customFields)
-
-
Method Details
-
start
public void start()- Specified by:
start
in interfaceLifeCycle
- Overrides:
start
in classAbstractCompositeJsonFormatter<ILoggingEvent>
-
configureProviderFieldNames
protected void configureProviderFieldNames() -
isIncludeCallerData
public boolean isIncludeCallerData() -
setIncludeCallerData
public void setIncludeCallerData(boolean includeCallerData) -
getCustomFieldsAsString
-
setCustomFieldsFromString
-
setCustomFields
-
getCustomFields
-
getShortenedLoggerNameLength
public int getShortenedLoggerNameLength() -
setShortenedLoggerNameLength
public void setShortenedLoggerNameLength(int length) -
isIncludeMdc
public boolean isIncludeMdc() -
setIncludeMdc
public void setIncludeMdc(boolean includeMdc) -
isIncludeTags
public boolean isIncludeTags() -
setIncludeTags
public void setIncludeTags(boolean includeTags) -
isIncludeStructuredArguments
public boolean isIncludeStructuredArguments() -
setIncludeStructuredArguments
public void setIncludeStructuredArguments(boolean includeStructuredArguments) -
isIncludeNonStructuredArguments
public boolean isIncludeNonStructuredArguments() -
setIncludeNonStructuredArguments
public void setIncludeNonStructuredArguments(boolean includeNonStructuredArguments) -
getNonStructuredArgumentsFieldPrefix
-
setNonStructuredArgumentsFieldPrefix
-
getIncludeMdcKeyNames
-
addIncludeMdcKeyName
-
setIncludeMdcKeyNames
-
getExcludeMdcKeyNames
-
addExcludeMdcKeyName
-
setExcludeMdcKeyNames
-
addMdcKeyFieldName
-
isIncludeContext
public boolean isIncludeContext() -
setIncludeContext
public void setIncludeContext(boolean includeContext) -
getThrowableConverter
-
setThrowableConverter
-
getVersion
-
setVersion
-
isWriteVersionAsInteger
public boolean isWriteVersionAsInteger() -
setWriteVersionAsInteger
public void setWriteVersionAsInteger(boolean writeVersionAsInteger) -
getMessageSplitRegex
Write the message as a JSON array by splitting the message text using the specified regex.- Returns:
- The regex used to split the message text
-
setMessageSplitRegex
Write the message as a JSON array by splitting the message text using the specified regex.The allowed values are:
- Null/Empty : Disable message splitting. This is also the default behavior.
- Any valid regex : Use the specified regex.
SYSTEM
: Use the system-default line separator.UNIX
: Use\n
.WINDOWS
: Use\r\n
.
#+
, then the logging statement:log.info("First line##Second line###Third line")
will produce:{ ... "message": [ "First line", "Second line", "Third line" ], ... }
- Parameters:
messageSplitRegex
- The regex used to split the message text
-
addProvider
-
getProviders
- Overrides:
getProviders
in classAbstractCompositeJsonFormatter<ILoggingEvent>
-
getFieldNames
-
setFieldNames
-
getTimeZone
-
setTimeZone
-
getTimestampPattern
-
setTimestampPattern
-
setProviders
- Overrides:
setProviders
in classLoggingEventCompositeJsonFormatter
-