Class AbstractJsonPatternParser<Event>

java.lang.Object
net.logstash.logback.pattern.AbstractJsonPatternParser<Event>
Type Parameters:
Event - - type of the event (ILoggingEvent, IAccessEvent)
Direct Known Subclasses:
AccessEventJsonPatternParser, LoggingEventJsonPatternParser

public abstract class AbstractJsonPatternParser<Event> extends Object
Parser that takes a JSON pattern, resolves all the conversion specifiers and returns an instance of NodeWriter that, when its write() method is invoked, produces JSON defined by the parsed pattern.
Author:
Dmitry Andrianov
  • Field Details

    • OPERATION_PATTERN

      public static final Pattern OPERATION_PATTERN
      Pattern used to parse and detect AbstractJsonPatternParser.Operation in a string. An operation starts with a #, followed by a name and a pair of {} with possible arguments in between.
  • Method Details

    • addOperation

      protected void addOperation(String name, AbstractJsonPatternParser.Operation<?> operation)
      Register a new AbstractJsonPatternParser.Operation and bind it to the given name.
      Parameters:
      name - the name of the operation
      operation - the AbstractJsonPatternParser.Operation instance
    • makeLayoutValueGetter

      protected ValueGetter<Event,String> makeLayoutValueGetter(String data)
    • buildLayout

      protected PatternLayoutAdapter<Event> buildLayout(String format)
      Initialize a PatternLayout with the supplied format and throw an IllegalArgumentException if the format is invalid.
      Parameters:
      format - the pattern layout format
      Returns:
      a configured and started PatternLayoutAdapter instance around the supplied format
      Throws:
      IllegalArgumentException - if the supplied format is not a valid PatternLayout
    • createLayout

      protected abstract PatternLayoutBase<Event> createLayout()
      Create a PatternLayout instance of the appropriate type. The returned instance will be further configured with the context and appropriate pattern then started.
      Returns:
      an unstarted PatternLayoutBase instance
    • parse

      Parse a JSON pattern and produce the corresponding NodeWriter. Returns null if the pattern is invalid, null or empty. An error status is logged when the pattern is invalid and parsing failed.
      Parameters:
      pattern - the JSON pattern to parse
      Returns:
      a NodeWriter configured according to the pattern
      Throws:
      AbstractJsonPatternParser.JsonPatternException - denotes an invalid pattern
    • isOmitEmptyFields

      public boolean isOmitEmptyFields()
      When true, fields whose values are considered empty will be omitted from JSON output.
      Returns:
      true if fields with empty values are omitted from JSON output
    • setOmitEmptyFields

      public void setOmitEmptyFields(boolean omitEmptyFields)
      When true, fields whose values are considered empty will be omitted from JSON output.
      Parameters:
      omitEmptyFields - whether fields with empty value should be omitted or not