Class MessageBuilder<T>

  • Type Parameters:
    T - The message type being built.
    Direct Known Subclasses:
    BaseMessageFormatter

    public abstract class MessageBuilder<T>
    extends Object
    A builder which is used during message parsing to create a message object which encapsulates all the formatting requirements of a log message. One message builder is created for each log message that's parsed.
    See Also:
    Original Java code of Google Flogger
    • Constructor Detail

    • Method Detail

      • getParser

        public final MessageParser getParser()
        Returns the parser used to process the log format message in this builder.
      • getMessage

        public final String getMessage()
        Returns the log format message to be parsed by this builder.
      • getExpectedArgumentCount

        public final int getExpectedArgumentCount()
        Returns the expected number of arguments to be formatted by this message. This is only valid once parsing has completed successfully.
      • addParameter

        public final void addParameter​(int termStart,
                                       int termEnd,
                                       Parameter param)
        Called by parser implementations to signify that the parsing of the next parameter is complete. This method will call addParameterImpl(int, int, Parameter) with exactly the same arguments, but may also do additional work before or after that call.
        Parameters:
        termStart - the index of the first character in the log message string that was parsed to form the given parameter.
        termEnd - the index after the last character in the log message string that was parsed to form the given parameter.
        param - a parameter representing the format specified by the substring of the log message in the range [termStart, termEnd).
      • addParameterImpl

        protected abstract void addParameterImpl​(int termStart,
                                                 int termEnd,
                                                 Parameter param)
        Adds the specified parameter to the format instance currently being built. This method is to signify that the parsing of the next parameter is complete.

        Note that each successive call to this method during parsing will specify a disjoint ranges of characters from the log message and that each range will be higher that the previously specified one.

        Parameters:
        termStart - the index of the first character in the log message string that was parsed to form the given parameter.
        termEnd - the index after the last character in the log message string that was parsed to form the given parameter.
        param - a parameter representing the format specified by the substring of the log message in the range [termStart, termEnd).
      • buildImpl

        protected abstract T buildImpl()
        Returns the implementation specific result of parsing the current log message.
      • build

        public final T build()
        Builds a log message using the current message context.
        Returns:
        the implementation specific result of parsing the current log message.