public final class MementoMessage extends java.lang.Object implements Message, StringBuilderFormattable
MementoMessage is intended to be used when we need to make an
immutable copy of a Message without forgetting the original
Message.getFormat() and Message.getParameters() values.| Modifier and Type | Field and Description |
|---|---|
private java.lang.String |
format |
private java.lang.String |
formattedMessage |
private java.lang.Object[] |
parameters |
| Constructor and Description |
|---|
MementoMessage(java.lang.String formattedMessage,
java.lang.String format,
java.lang.Object[] parameters) |
| Modifier and Type | Method and Description |
|---|---|
void |
formatTo(java.lang.StringBuilder buffer)
Writes a text representation of this object into the specified
StringBuilder, ideally without allocating
temporary objects. |
java.lang.String |
getFormat()
Gets the format portion of the Message.
|
java.lang.String |
getFormattedMessage()
Gets the Message formatted as a String.
|
java.lang.Object[] |
getParameters()
Gets parameter values, if any.
|
java.lang.Throwable |
getThrowable()
Always returns null.
|
java.lang.String |
toString() |
private final java.lang.String formattedMessage
private final java.lang.String format
private final java.lang.Object[] parameters
public MementoMessage(java.lang.String formattedMessage,
java.lang.String format,
java.lang.Object[] parameters)
public java.lang.String getFormattedMessage()
Message
When configured to log asynchronously, this method is called before the Message is queued, unless this
message implements ReusableMessage or is annotated with AsynchronouslyFormattable.
This gives the Message implementation class a chance to create a formatted message String with the current value
of any mutable objects.
The intention is that the Message implementation caches this formatted message and returns it on subsequent
calls. (See LOG4J2-763.)
When logging synchronously, this method will not be called for Messages that implement the
StringBuilderFormattable interface: instead, the
formatTo(StringBuilder) method will be called so the
Message can format its contents without creating intermediate String objects.
getFormattedMessage in interface Messagepublic java.lang.String getFormat()
MessagegetFormat in interface Messagepublic java.lang.Object[] getParameters()
MessagegetParameters in interface Messagepublic java.lang.Throwable getThrowable()
getThrowable in interface Messagepublic void formatTo(java.lang.StringBuilder buffer)
StringBuilderFormattableStringBuilder, ideally without allocating
temporary objects.formatTo in interface StringBuilderFormattablebuffer - the StringBuilder to write intopublic java.lang.String toString()
toString in class java.lang.Object