Class MementoMessage
- java.lang.Object
-
- org.apache.logging.log4j.core.impl.MementoMessage
-
- All Implemented Interfaces:
java.io.Serializable,Message,StringBuilderFormattable
public final class MementoMessage extends java.lang.Object implements Message, StringBuilderFormattable
Consider this class private.MementoMessageis intended to be used when we need to make an immutable copy of aMessagewithout forgetting the originalMessage.getFormat()andMessage.getParameters()values.- Since:
- 3.0
- See Also:
- Serialized Form
-
-
Field Summary
Fields Modifier and Type Field Description private java.lang.Stringformatprivate java.lang.StringformattedMessageprivate java.lang.Object[]parameters
-
Constructor Summary
Constructors Constructor Description MementoMessage(java.lang.String formattedMessage, java.lang.String format, java.lang.Object[] parameters)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidformatTo(java.lang.StringBuilder buffer)Writes a text representation of this object into the specifiedStringBuilder, ideally without allocating temporary objects.java.lang.StringgetFormat()This method has unclear semantics and inconsistent implementations – its usage is strongly discouraged.java.lang.StringgetFormattedMessage()Gets the Message formatted as a String.java.lang.Object[]getParameters()Gets parameter values, if any.java.lang.ThrowablegetThrowable()Always returns null.java.lang.StringtoString()
-
-
-
Method Detail
-
getFormattedMessage
public java.lang.String getFormattedMessage()
Description copied from interface:MessageGets the Message formatted as a String. Each Message implementation determines the appropriate way to format the data encapsulated in the Message. Messages that provide more than one way of formatting the Message will implement MultiformatMessage.When configured to log asynchronously, this method is called before the Message is queued, unless this message implements
ReusableMessageor is annotated withAsynchronouslyFormattable. 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
StringBuilderFormattableinterface: instead, theformatTo(StringBuilder)method will be called so the Message can format its contents without creating intermediate String objects.- Specified by:
getFormattedMessagein interfaceMessage- Returns:
- The message String.
-
getFormat
public java.lang.String getFormat()
Description copied from interface:MessageThis method has unclear semantics and inconsistent implementations – its usage is strongly discouraged.
-
getParameters
public java.lang.Object[] getParameters()
Description copied from interface:MessageGets parameter values, if any.- Specified by:
getParametersin interfaceMessage- Returns:
- An array of parameter values or null.
-
getThrowable
public java.lang.Throwable getThrowable()
Always returns null.- Specified by:
getThrowablein interfaceMessage- Returns:
- null
-
formatTo
public void formatTo(java.lang.StringBuilder buffer)
Description copied from interface:StringBuilderFormattableWrites a text representation of this object into the specifiedStringBuilder, ideally without allocating temporary objects.- Specified by:
formatToin interfaceStringBuilderFormattable- Parameters:
buffer- the StringBuilder to write into
-
toString
public java.lang.String toString()
- Overrides:
toStringin classjava.lang.Object
-
-