Class MessageJsonProvider

All Implemented Interfaces:
ContextAware, FieldNamesAware<LogstashFieldNames>, JsonProvider<ILoggingEvent>

public class MessageJsonProvider extends AbstractFieldJsonProvider<ILoggingEvent> implements FieldNamesAware<LogstashFieldNames>
  • Field Details

  • Constructor Details

    • MessageJsonProvider

      public MessageJsonProvider()
  • Method Details

    • writeTo

      public void writeTo(JsonGenerator generator, ILoggingEvent event) throws IOException
      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 interface JsonProvider<ILoggingEvent>
      Parameters:
      generator - the JsonGenerator to produce JSON content
      event - the event to convert into JSON
      Throws:
      IOException - if an I/O error occurs
    • setFieldNames

      public void setFieldNames(LogstashFieldNames fieldNames)
      Specified by:
      setFieldNames in interface FieldNamesAware<LogstashFieldNames>
    • 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