public final class MementoMessage extends 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.Constructor and Description |
---|
MementoMessage(String formattedMessage,
String format,
Object[] parameters) |
Modifier and Type | Method and Description |
---|---|
void |
formatTo(StringBuilder buffer)
Writes a text representation of this object into the specified
StringBuilder , ideally without allocating
temporary objects. |
String |
getFormat()
Gets the format portion of the Message.
|
String |
getFormattedMessage()
Gets the Message formatted as a String.
|
Object[] |
getParameters()
Gets parameter values, if any.
|
Throwable |
getThrowable()
Always returns null.
|
String |
toString() |
public 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 Message
public String getFormat()
Message
getFormat
in interface Message
public Object[] getParameters()
Message
getParameters
in interface Message
public Throwable getThrowable()
getThrowable
in interface Message
public void formatTo(StringBuilder buffer)
StringBuilderFormattable
StringBuilder
, ideally without allocating
temporary objects.formatTo
in interface StringBuilderFormattable
buffer
- the StringBuilder to write intoCopyright © 1999-2019 The Apache Software Foundation. All Rights Reserved.
Apache Logging, Apache Log4j, Log4j, Apache, the Apache feather logo, the Apache Logging project logo, and the Apache Log4j logo are trademarks of The Apache Software Foundation.