Class LogstashFormatter

All Implemented Interfaces:
ContextAware, LifeCycle

public class LogstashFormatter extends LoggingEventCompositeJsonFormatter
A LoggingEventCompositeJsonFormatter that contains a common pre-defined set of JsonProviders. 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 Details

    • fieldNames

      protected LogstashFieldNames fieldNames
      The field names to use when writing the standard event fields
  • Constructor Details

    • LogstashFormatter

      public LogstashFormatter(ContextAware declaredOrigin)
    • LogstashFormatter

      public LogstashFormatter(ContextAware declaredOrigin, boolean includeCallerData)
    • LogstashFormatter

      public LogstashFormatter(ContextAware declaredOrigin, boolean includeCallerData, JsonNode customFields)
  • Method Details

    • start

      public void start()
      Specified by:
      start in interface LifeCycle
      Overrides:
      start in class AbstractCompositeJsonFormatter<ILoggingEvent>
    • configureProviderFieldNames

      protected void configureProviderFieldNames()
    • isIncludeCallerData

      public boolean isIncludeCallerData()
    • setIncludeCallerData

      public void setIncludeCallerData(boolean includeCallerData)
    • getCustomFieldsAsString

      public String getCustomFieldsAsString()
    • setCustomFieldsFromString

      public void setCustomFieldsFromString(String customFields)
    • setCustomFields

      public void setCustomFields(JsonNode customFields)
    • getCustomFields

      public JsonNode 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

      public String getNonStructuredArgumentsFieldPrefix()
    • setNonStructuredArgumentsFieldPrefix

      public void setNonStructuredArgumentsFieldPrefix(String nonStructuredArgumentsFieldPrefix)
    • getIncludeMdcKeyNames

      public List<String> getIncludeMdcKeyNames()
    • addIncludeMdcKeyName

      public void addIncludeMdcKeyName(String includedMdcKeyName)
    • setIncludeMdcKeyNames

      public void setIncludeMdcKeyNames(List<String> includeMdcKeyNames)
    • getExcludeMdcKeyNames

      public List<String> getExcludeMdcKeyNames()
    • addExcludeMdcKeyName

      public void addExcludeMdcKeyName(String excludedMdcKeyName)
    • setExcludeMdcKeyNames

      public void setExcludeMdcKeyNames(List<String> excludeMdcKeyNames)
    • addMdcKeyFieldName

      public void addMdcKeyFieldName(String mdcKeyFieldName)
    • isIncludeContext

      public boolean isIncludeContext()
    • setIncludeContext

      public void setIncludeContext(boolean includeContext)
    • getThrowableConverter

      public ThrowableHandlingConverter getThrowableConverter()
    • setThrowableConverter

      public void setThrowableConverter(ThrowableHandlingConverter throwableConverter)
    • getVersion

      public String getVersion()
    • setVersion

      public void setVersion(String version)
    • isWriteVersionAsInteger

      public boolean isWriteVersionAsInteger()
    • setWriteVersionAsInteger

      public void setWriteVersionAsInteger(boolean writeVersionAsInteger)
    • getMessageSplitRegex

      public String 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

      public void setMessageSplitRegex(String messageSplitRegex)
      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.
      For example, if this parameter is set to the regex #+, 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

      public void addProvider(JsonProvider<ILoggingEvent> provider)
    • getProviders

      public LoggingEventJsonProviders getProviders()
      Overrides:
      getProviders in class AbstractCompositeJsonFormatter<ILoggingEvent>
    • getFieldNames

      public LogstashFieldNames getFieldNames()
    • setFieldNames

      public void setFieldNames(LogstashFieldNames fieldNames)
    • getTimeZone

      public String getTimeZone()
    • setTimeZone

      public void setTimeZone(String timeZoneId)
    • getTimestampPattern

      public String getTimestampPattern()
    • setTimestampPattern

      public void setTimestampPattern(String pattern)
    • setProviders

      public void setProviders(JsonProviders<ILoggingEvent> jsonProviders)
      Overrides:
      setProviders in class LoggingEventCompositeJsonFormatter