org.apache.logging.log4j.message
Class MapMessage

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

public class MapMessage
extends Object
implements MultiformatMessage, Serializable

Represents a Message that consists of a Map.

See Also:
Serialized Form

Nested Class Summary
static class MapMessage.MapFormat
          When set as the format specifier causes the Map to be formatted as XML.
 
Constructor Summary
MapMessage()
          Constructor.
MapMessage(Map<String,String> map)
          Constructor based on an existing Map.
 
Method Summary
protected  void appendMap(StringBuilder sb)
           
protected  void asJava(StringBuilder sb)
           
protected  void asJSON(StringBuilder sb)
           
 String asString()
          Format the Structured data as described in RFC 5424.
 String asString(String format)
           
 void asXML(StringBuilder sb)
           
 void clear()
          Clear the data.
 boolean equals(Object o)
           
 String get(String key)
          Retrieve the value of the element with the specified key or null if the key is not present.
 Map<String,String> getData()
          Return the message data as an unmodifiable Map.
 String getFormattedMessage()
          Format the message and return it.
 String getFormattedMessage(String[] formats)
          Returns the Message formatted as a String.
 String getMessageFormat()
          Return the message.
 Object[] getParameters()
          Return the data elements as if they were parameters on the logging event.
 int hashCode()
           
 MapMessage newInstance(Map<String,String> map)
           
 void put(String key, String value)
          Add an item to the data Map.
 void putAll(Map<String,String> map)
          Add all the elements from the specified Map.
 String remove(String key)
          Remove the element with the specified name.
 String toString()
           
protected  void validate(String key, String value)
           
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

MapMessage

public MapMessage()
Constructor.


MapMessage

public MapMessage(Map<String,String> map)
Constructor based on an existing Map.

Parameters:
map - The Map.
Method Detail

getParameters

public Object[] getParameters()
Return the data elements as if they were parameters on the logging event.

Specified by:
getParameters in interface Message
Returns:
the data elements.

getMessageFormat

public String getMessageFormat()
Return the message.

Specified by:
getMessageFormat in interface Message
Returns:
the message.

getData

public Map<String,String> getData()
Return the message data as an unmodifiable Map.

Returns:
the message data as an unmodifiable map.

clear

public void clear()
Clear the data.


put

public void put(String key,
                String value)
Add an item to the data Map.

Parameters:
key - The name of the data item.
value - The value of the data item.

validate

protected void validate(String key,
                        String value)

putAll

public void putAll(Map<String,String> map)
Add all the elements from the specified Map.

Parameters:
map - The Map to add.

get

public String get(String key)
Retrieve the value of the element with the specified key or null if the key is not present.

Parameters:
key - The name of the element.
Returns:
The value of the element or null if the key is not present.

remove

public String remove(String key)
Remove the element with the specified name.

Parameters:
key - The name of the element.
Returns:
The previous value of the element.

asString

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

Returns:
The formatted String.

asString

public String asString(String format)

asXML

public void asXML(StringBuilder sb)

getFormattedMessage

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

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

getFormattedMessage

public String getFormattedMessage(String[] formats)
Description copied from interface: MultiformatMessage
Returns the Message formatted as a String.

Specified by:
getFormattedMessage in interface MultiformatMessage
Parameters:
formats - An array of Strings that provide extra information about how to format the message. MapMessage uses the first format specifier it recognizes. The supported formats are XML, JSON, and JAVA. The default format is key1="value1" key2="value2" as required by RFC 5424 messages.
Returns:
The formatted message.

appendMap

protected void appendMap(StringBuilder sb)

asJSON

protected void asJSON(StringBuilder sb)

asJava

protected void asJava(StringBuilder sb)

newInstance

public MapMessage newInstance(Map<String,String> map)

toString

public String toString()
Overrides:
toString in class Object

equals

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

hashCode

public int hashCode()
Overrides:
hashCode in class Object


Copyright © 1999-2012 Apache Software Foundation. All Rights Reserved.