public class MapMessage extends Object implements MultiformatMessage
Thread-safety note: the contents of this message can be modified after construction. When using asynchronous loggers and appenders it is not recommended to modify this message after the message is logged, because it is undefined whether the logged message string will contain the old values or the modified values.
Modifier and Type | Class and Description |
---|---|
static class |
MapMessage.MapFormat
When set as the format specifier causes the Map to be formatted as XML.
|
Constructor and Description |
---|
MapMessage()
Constructor.
|
MapMessage(Map<String,String> map)
Constructor based on an existing Map.
|
Modifier and Type | Method and Description |
---|---|
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()
Returns the message data as an unmodifiable Map.
|
String |
getFormat()
Returns the message.
|
String[] |
getFormats()
Returns the supported formats.
|
String |
getFormattedMessage()
Format the message and return it.
|
String |
getFormattedMessage(String[] formats)
Returns the Message formatted as a String.
|
Object[] |
getParameters()
Returns the data elements as if they were parameters on the logging event.
|
Throwable |
getThrowable()
Always returns null.
|
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) |
public MapMessage()
public MapMessage(Map<String,String> map)
map
- The Map.public String[] getFormats()
MultiformatMessage
getFormats
in interface MultiformatMessage
public Object[] getParameters()
getParameters
in interface Message
public Map<String,String> getData()
public void clear()
public void put(String key, String value)
key
- The name of the data item.value
- The value of the data item.public void putAll(Map<String,String> map)
map
- The Map to add.public String get(String key)
key
- The name of the element.public String remove(String key)
key
- The name of the element.public String asString()
public void asXml(StringBuilder sb)
public String getFormattedMessage()
getFormattedMessage
in interface Message
public String getFormattedMessage(String[] formats)
MultiformatMessage
getFormattedMessage
in interface MultiformatMessage
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.protected void appendMap(StringBuilder sb)
protected void asJson(StringBuilder sb)
protected void asJava(StringBuilder sb)
public MapMessage newInstance(Map<String,String> map)
public Throwable getThrowable()
getThrowable
in interface Message
Copyright © 1999-2021 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.