Class ReusableSimpleMessage
- All Implemented Interfaces:
Serializable
,CharSequence
,Message
,ParameterVisitable
,ReusableMessage
,StringBuilderFormattable
- Since:
- 2.6
- See Also:
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionchar
charAt
(int index) void
clear()
<S> void
forEachParameter
(ParameterConsumer<S> action, S state) Performs the given action for each parameter until all values have been processed or the action throws an exception.void
formatTo
(StringBuilder buffer) Writes a text representation of this object into the specifiedStringBuilder
, ideally without allocating temporary objects.Gets the format portion of the Message.Gets the Message formatted as a String.short
This message does not have any parameters so this method always returns zero.Object[]
Gets parameter values, if any.Gets the throwable, if any.int
length()
memento()
Returns an immutable snapshot of the current internal state of this reusable message.void
set
(CharSequence charSequence) void
subSequence
(int start, int end) Object[]
swapParameters
(Object[] emptyReplacement) This message does not have any parameters, so this method returns the specified array.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface java.lang.CharSequence
chars, codePoints, toString
-
Constructor Details
-
ReusableSimpleMessage
public ReusableSimpleMessage()
-
-
Method Details
-
set
-
set
-
getFormattedMessage
Description copied from interface:Message
Gets 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
ReusableMessage
or 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
StringBuilderFormattable
interface: instead, theformatTo(StringBuilder)
method will be called so the Message can format its contents without creating intermediate String objects.- Specified by:
getFormattedMessage
in interfaceMessage
- Returns:
- The message String.
-
getFormat
Description copied from interface:Message
Gets the format portion of the Message.- Specified by:
getFormat
in interfaceMessage
- Returns:
- The message format. Some implementations, such as ParameterizedMessage, will use this as the message "pattern". Other Messages may simply return an empty String. TODO Do all messages have a format? What syntax? Using a Formatter object could be cleaner. (RG) In SimpleMessage the format is identical to the formatted message. In ParameterizedMessage and StructuredDataMessage it is not. It is up to the Message implementer to determine what this method will return. A Formatter is inappropriate as this is very specific to the Message implementation so it isn't clear to me how having a Formatter separate from the Message would be cleaner.
-
getParameters
Description copied from interface:Message
Gets parameter values, if any.- Specified by:
getParameters
in interfaceMessage
- Returns:
- An array of parameter values or null.
-
getThrowable
Description copied from interface:Message
Gets the throwable, if any.- Specified by:
getThrowable
in interfaceMessage
- Returns:
- the throwable or null.
-
formatTo
Description copied from interface:StringBuilderFormattable
Writes a text representation of this object into the specifiedStringBuilder
, ideally without allocating temporary objects.- Specified by:
formatTo
in interfaceStringBuilderFormattable
- Parameters:
buffer
- the StringBuilder to write into
-
swapParameters
This message does not have any parameters, so this method returns the specified array.- Specified by:
swapParameters
in interfaceReusableMessage
- Parameters:
emptyReplacement
- the parameter array to return- Returns:
- the specified array
- See Also:
-
getParameterCount
public short getParameterCount()This message does not have any parameters so this method always returns zero.- Specified by:
getParameterCount
in interfaceReusableMessage
- Returns:
- 0 (zero)
-
forEachParameter
Description copied from interface:ParameterVisitable
Performs 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:
forEachParameter
in 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
Description copied from interface:ReusableMessage
Returns 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:
memento
in interfaceReusableMessage
- Returns:
- an immutable snapshot of this message
-
length
public int length()- Specified by:
length
in interfaceCharSequence
-
charAt
public char charAt(int index) - Specified by:
charAt
in interfaceCharSequence
-
subSequence
- Specified by:
subSequence
in interfaceCharSequence
-
clear
public void clear()
-