org.apache.logging.log4j.message
Interface Message

All Superinterfaces:
Serializable
All Known Subinterfaces:
MultiformatMessage
All Known Implementing Classes:
FormattedMessage, LocalizedMessage, MapMessage, MessageFormatMessage, ObjectMessage, ParameterizedMessage, SimpleMessage, StringFormattedMessage, StructuredDataMessage, ThreadDumpMessage

public interface Message
extends Serializable

An interface for various Message implementations that can be logged. Messages can act as wrappers around Objects so that user can have control over converting Objects to Strings when necessary without requiring complicated formatters and as a way to manipulate the message based on information available at runtime such as the locale of the system.

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.

Troublesome:
Interfaces should rarely extend Serializable according to Effective Java 2nd Ed pg 291. (RG) That section also says "If a class or interface exists primarily to participate in a framework that requires all participants to implement Serializable, then it makes perfect sense for the class or interface to implement or extend Serializable". Such is the case here as the LogEvent must be Serializable.

Method Summary
 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()
          Gets the throwable, if any.
 

Method Detail

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.

Returns:
The message String.

getFormat

String getFormat()
Gets the format portion of the Message.

Returns:
The message format. Some implementations, such as ParameterizedMessage, will use this as the message "pattern". Other Messages may simply return an empty String.
Troublesome:
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

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.


Copyright © 1999-2014 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.