org.apache.logging.log4j.message
Class StructuredDataMessage

java.lang.Object
  extended by org.apache.logging.log4j.message.MapMessage
      extended by org.apache.logging.log4j.message.StructuredDataMessage
All Implemented Interfaces:
Serializable, Message, MultiformatMessage

public class StructuredDataMessage
extends MapMessage
implements MultiformatMessage, Serializable

Represents a Message that conforms to RFC 5424 (http://tools.ietf.org/html/rfc5424).

See Also:
Serialized Form

Nested Class Summary
static class StructuredDataMessage.Format
          Supported formats.
 
Nested classes/interfaces inherited from class org.apache.logging.log4j.message.MapMessage
MapMessage.MapFormat
 
Constructor Summary
protected StructuredDataMessage()
          Basic constructor.
  StructuredDataMessage(String id, String msg, String type)
          Constructor based on a String id.
  StructuredDataMessage(String id, String msg, String type, Map<String,String> data)
          Constructor based on a String id.
  StructuredDataMessage(StructuredDataId id, String msg, String type)
          Constructor based on a StructuredDataId.
  StructuredDataMessage(StructuredDataId id, String msg, String type, Map<String,String> data)
          Constructor based on a StructuredDataId.
 
Method Summary
 String asString()
          Format the Structured data as described in RFC 5424.
 String asString(String format)
          Format the Structured data as described in RFC 5424.
 String asString(StructuredDataMessage.Format format, StructuredDataId structuredDataId)
          Format the Structured data as described in RFC 5424.
 boolean equals(Object o)
           
 String getFormat()
          Returns the message.
 String[] getFormats()
          Returns the supported formats.
 String getFormattedMessage()
          Format the message and return it.
 String getFormattedMessage(String[] formats)
          Format the message according the the specified format.
 StructuredDataId getId()
          Returns the id.
 String getType()
          Set the type.
 int hashCode()
           
 MapMessage newInstance(Map<String,String> map)
           
protected  void setId(String id)
          Set the id from a String.
protected  void setId(StructuredDataId id)
          Set the id.
protected  void setMessageFormat(String msg)
           
protected  void setType(String type)
           
 String toString()
           
protected  void validate(String key, String value)
           
 
Methods inherited from class org.apache.logging.log4j.message.MapMessage
appendMap, asJava, asJSON, asXML, clear, get, getData, getParameters, put, putAll, remove
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface org.apache.logging.log4j.message.Message
getParameters
 

Constructor Detail

StructuredDataMessage

public StructuredDataMessage(String id,
                             String msg,
                             String type)
Constructor based on a String id.

Parameters:
id - The String id.
msg - The message.
type - The message type.

StructuredDataMessage

public StructuredDataMessage(String id,
                             String msg,
                             String type,
                             Map<String,String> data)
Constructor based on a String id.

Parameters:
id - The String id.
msg - The message.
type - The message type.
data - The StructuredData map.

StructuredDataMessage

public StructuredDataMessage(StructuredDataId id,
                             String msg,
                             String type)
Constructor based on a StructuredDataId.

Parameters:
id - The StructuredDataId.
msg - The message.
type - The message type.

StructuredDataMessage

public StructuredDataMessage(StructuredDataId id,
                             String msg,
                             String type,
                             Map<String,String> data)
Constructor based on a StructuredDataId.

Parameters:
id - The StructuredDataId.
msg - The message.
type - The message type.
data - The StructuredData map.

StructuredDataMessage

protected StructuredDataMessage()
Basic constructor.

Method Detail

getFormats

public String[] getFormats()
Returns the supported formats.

Specified by:
getFormats in interface MultiformatMessage
Overrides:
getFormats in class MapMessage
Returns:
An array of the supported format names.

getId

public StructuredDataId getId()
Returns the id.

Returns:
the StructuredDataId.

setId

protected void setId(String id)
Set the id from a String.

Parameters:
id - The String id.

setId

protected void setId(StructuredDataId id)
Set the id.

Parameters:
id - The StructuredDataId.

getType

public String getType()
Set the type.

Returns:
the type.

setType

protected void setType(String type)

getFormat

public String getFormat()
Returns the message.

Specified by:
getFormat in interface Message
Overrides:
getFormat in class MapMessage
Returns:
the message.

setMessageFormat

protected void setMessageFormat(String msg)

validate

protected void validate(String key,
                        String value)
Overrides:
validate in class MapMessage

asString

public String asString()
Format the Structured data as described in RFC 5424.

Overrides:
asString in class MapMessage
Returns:
The formatted String.

asString

public String asString(String format)
Format the Structured data as described in RFC 5424.

Overrides:
asString in class MapMessage
Parameters:
format - The format identifier. Ignored in this implementation.
Returns:
The formatted String.

asString

public final String asString(StructuredDataMessage.Format format,
                             StructuredDataId structuredDataId)
Format the Structured data as described in RFC 5424.

Parameters:
format - "full" will include the type and message. null will return only the STRUCTURED-DATA as described in RFC 5424
structuredDataId - The SD-ID as described in RFC 5424. If null the value in the StructuredData will be used.
Returns:
The formatted String.

getFormattedMessage

public String getFormattedMessage()
Format the message and return it.

Specified by:
getFormattedMessage in interface Message
Overrides:
getFormattedMessage in class MapMessage
Returns:
the formatted message.

getFormattedMessage

public String getFormattedMessage(String[] formats)
Format the message according the the specified format.

Specified by:
getFormattedMessage in interface MultiformatMessage
Overrides:
getFormattedMessage in class MapMessage
Parameters:
formats - An array of Strings that provide extra information about how to format the message. StructuredDataMessage accepts only a format of "FULL" which will cause the event type to be prepended and the event message to be appended. Specifying any other value will cause only the StructuredData to be included. The default is "FULL".
Returns:
the formatted message.

toString

public String toString()
Overrides:
toString in class MapMessage

newInstance

public MapMessage newInstance(Map<String,String> map)
Overrides:
newInstance in class MapMessage

equals

public boolean equals(Object o)
Overrides:
equals in class MapMessage

hashCode

public int hashCode()
Overrides:
hashCode in class MapMessage


Copyright © 1999-2012 Apache Software Foundation. All Rights Reserved. Apache Logging, Apache Log4j, Log4j, Apache, the Apache feather logo, and the Apache Logging project logo are trademarks of The Apache Software Foundation.