Class ReusableSimpleMessage
- java.lang.Object
-
- org.apache.logging.log4j.message.ReusableSimpleMessage
-
- All Implemented Interfaces:
java.io.Serializable,java.lang.CharSequence,Clearable,Message,ParameterVisitable,ReusableMessage,StringBuilderFormattable
public class ReusableSimpleMessage extends java.lang.Object implements ReusableMessage, java.lang.CharSequence, ParameterVisitable, Clearable
Mutable Message wrapper around a String message.- Since:
- 2.6
- See Also:
- Serialized Form
-
-
Field Summary
Fields Modifier and Type Field Description private java.lang.CharSequencecharSequenceprivate static longserialVersionUID
-
Constructor Summary
Constructors Constructor Description ReusableSimpleMessage()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description charcharAt(int index)voidclear()Resets the object to a clean state.<S> voidforEachParameter(ParameterConsumer<S> action, S state)Performs the given action for each parameter until all values have been processed or the action throws an exception.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.shortgetParameterCount()This message does not have any parameters so this method always returns zero.java.lang.Object[]getParameters()Gets parameter values, if any.java.lang.ThrowablegetThrowable()Gets the throwable, if any.intlength()Messagememento()Returns an immutable snapshot of the current internal state of this reusable message.voidset(java.lang.CharSequence charSequence)voidset(java.lang.String message)java.lang.CharSequencesubSequence(int start, int end)java.lang.Object[]swapParameters(java.lang.Object[] emptyReplacement)This message does not have any parameters, so this method returns the specified array.private java.lang.ObjectwriteReplace()
-
-
-
Field Detail
-
serialVersionUID
private static final long serialVersionUID
- See Also:
- Constant Field Values
-
charSequence
private java.lang.CharSequence charSequence
-
-
Method Detail
-
set
public void set(java.lang.String message)
-
set
public void set(java.lang.CharSequence charSequence)
-
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()
Description copied from interface:MessageGets the throwable, if any.- Specified by:
getThrowablein interfaceMessage- Returns:
- the throwable or 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
-
swapParameters
public java.lang.Object[] swapParameters(java.lang.Object[] emptyReplacement)
This message does not have any parameters, so this method returns the specified array.- Specified by:
swapParametersin interfaceReusableMessage- Parameters:
emptyReplacement- the parameter array to return- Returns:
- the specified array
- See Also:
ReusableMessage.getParameterCount()
-
getParameterCount
public short getParameterCount()
This message does not have any parameters so this method always returns zero.- Specified by:
getParameterCountin interfaceReusableMessage- Returns:
- 0 (zero)
-
forEachParameter
public <S> void forEachParameter(ParameterConsumer<S> action, S state)
Description copied from interface:ParameterVisitablePerforms the given action for each parameter until all values have been processed or the action throws an exception.The second parameter lets callers pass in a stateful object to be modified with the key-value pairs, so the TriConsumer implementation itself can be stateless and potentially reusable.
- Specified by:
forEachParameterin interfaceParameterVisitable- Type Parameters:
S- type of the third parameter- Parameters:
action- The action to be performed for each key-value pair in this collectionstate- the object to be passed as the third parameter to each invocation on the specified ParameterConsumer.
-
memento
public Message memento()
Description copied from interface:ReusableMessageReturns an immutable snapshot of the current internal state of this reusable message. The returned snapshot will not be affected by subsequent modifications of this reusable message.- Specified by:
mementoin interfaceReusableMessage- Returns:
- an immutable snapshot of this message
-
length
public int length()
- Specified by:
lengthin interfacejava.lang.CharSequence
-
charAt
public char charAt(int index)
- Specified by:
charAtin interfacejava.lang.CharSequence
-
subSequence
public java.lang.CharSequence subSequence(int start, int end)- Specified by:
subSequencein interfacejava.lang.CharSequence
-
clear
public void clear()
Description copied from interface:ClearableResets the object to a clean state.
-
writeReplace
private java.lang.Object writeReplace()
-
-