Class Log4j2Message

  • All Implemented Interfaces:
    Serializable, org.apache.logging.log4j.message.Message, org.apache.logging.log4j.util.MessageSupplier, org.apache.logging.log4j.util.StringBuilderFormattable

    public final class Log4j2Message
    extends Object
    implements org.apache.logging.log4j.util.MessageSupplier, org.apache.logging.log4j.message.Message, org.apache.logging.log4j.util.StringBuilderFormattable
    This class converts a message with arguments into a Log4j2 Message.

    When a log message is ignored (e.g. not printed in log files), Log4j2 processes MessageSupplier objects twice faster than Message objects (even if message is not formatted).

    Having the same object implementing both MessageSupplier and Message is a bit faster than two separate objects.

    Benchmarks don't show significant performance improvements by implementing StringBuilderFormattable but it can't hurt and seems to be the norm other implementations

    See Also:
    Serialized Form
    • Method Detail

      • getMessage

        public String getMessage()
      • get

        public org.apache.logging.log4j.message.Message get()
        Specified by:
        get in interface org.apache.logging.log4j.util.MessageSupplier
      • getFormattedMessage

        public String getFormattedMessage()
        Specified by:
        getFormattedMessage in interface org.apache.logging.log4j.message.Message
      • formatTo

        public void formatTo​(StringBuilder buffer)
        Specified by:
        formatTo in interface org.apache.logging.log4j.util.StringBuilderFormattable
      • getFormat

        public String getFormat()
        Specified by:
        getFormat in interface org.apache.logging.log4j.message.Message
      • getParameters

        public Object[] getParameters()
        Specified by:
        getParameters in interface org.apache.logging.log4j.message.Message
      • getThrowable

        public Throwable getThrowable()
        Specified by:
        getThrowable in interface org.apache.logging.log4j.message.Message