Interface Message
- All Superinterfaces:
Serializable
- All Known Subinterfaces:
EntryMessage
,ExitMessage
,FlowMessage
,MessageCollectionMessage<T>
,MultiformatMessage
,MultiFormatStringBuilderFormattable
,ReusableMessage
- All Known Implementing Classes:
FormattedMessage
,LocalizedMessage
,MapMessage
,MessageFormatMessage
,ObjectArrayMessage
,ObjectMessage
,ParameterizedMessage
,ReusableObjectMessage
,ReusableParameterizedMessage
,ReusableSimpleMessage
,SimpleMessage
,StringFormattedMessage
,StringMapMessage
,StructuredDataCollectionMessage
,StructuredDataMessage
,ThreadDumpMessage
Custom Message implementations should consider implementing the StringBuilderFormattable
interface for more efficient processing. Garbage-free Layouts will call
formatTo(StringBuilder)
instead of
getFormattedMessage()
if the Message implements StringBuilderFormattable.
Note: Message objects should not be considered to be thread safe nor should they be assumed to be safely reusable even on the same thread. The logging system may provide information to the Message objects and the Messages might be queued for asynchronous delivery. Thus, any modifications to a Message object by an application should by avoided after the Message has been passed as a parameter on a Logger method.
- See Also:
-
Method Details
-
getFormattedMessage
String getFormattedMessage()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.- Returns:
- The message String.
-
getFormat
Deprecated.Deprecated since version2.24.0
. UseMultiformatMessage
instead to implement messages that can format themselves in one or more encodings.This method has unclear semantics and inconsistent implementations – its usage is strongly discouraged. -
getParameters
Object[] getParameters()Gets parameter values, if any.- Returns:
- An array of parameter values or null.
-
getThrowable
Throwable getThrowable()Gets the throwable, if any.- Returns:
- the throwable or null.
-
2.24.0
.