@AsynchronouslyFormattable public class MapMessage extends java.lang.Object implements MultiformatMessage, StringBuilderFormattable
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.
|
Modifier and Type | Field and Description |
---|---|
private IndexedStringMap |
data |
private static long |
serialVersionUID |
Constructor and Description |
---|
MapMessage()
Constructor.
|
MapMessage(java.util.Map<java.lang.String,java.lang.String> map)
Constructor based on an existing Map.
|
Modifier and Type | Method and Description |
---|---|
protected void |
appendMap(java.lang.StringBuilder sb) |
protected void |
asJava(java.lang.StringBuilder sb) |
protected void |
asJson(java.lang.StringBuilder sb) |
java.lang.String |
asString()
Format the Structured data as described in RFC 5424.
|
java.lang.String |
asString(java.lang.String format) |
void |
asXml(java.lang.StringBuilder sb) |
void |
clear()
Clear the data.
|
boolean |
equals(java.lang.Object o) |
private java.lang.StringBuilder |
format(MapMessage.MapFormat format,
java.lang.StringBuilder sb)
Format the Structured data as described in RFC 5424.
|
void |
formatTo(java.lang.StringBuilder buffer)
Writes a text representation of this object into the specified
StringBuilder , ideally without allocating
temporary objects. |
java.lang.String |
get(java.lang.String key)
Retrieve the value of the element with the specified key or null if the key is not present.
|
java.util.Map<java.lang.String,java.lang.String> |
getData()
Returns the message data as an unmodifiable Map.
|
java.lang.String |
getFormat()
Returns the message.
|
java.lang.String[] |
getFormats()
Returns the supported formats.
|
java.lang.String |
getFormattedMessage()
Format the message and return it.
|
java.lang.String |
getFormattedMessage(java.lang.String[] formats)
Returns the Message formatted as a String.
|
IndexedReadOnlyStringMap |
getIndexedReadOnlyStringMap()
Returns a read-only view of the message data.
|
java.lang.Object[] |
getParameters()
Returns the data elements as if they were parameters on the logging event.
|
java.lang.Throwable |
getThrowable()
Always returns null.
|
int |
hashCode() |
MapMessage |
newInstance(java.util.Map<java.lang.String,java.lang.String> map) |
void |
put(java.lang.String key,
java.lang.String value)
Add an item to the data Map.
|
void |
putAll(java.util.Map<java.lang.String,java.lang.String> map)
Add all the elements from the specified Map.
|
java.lang.String |
remove(java.lang.String key)
Remove the element with the specified name.
|
java.lang.String |
toString() |
protected void |
validate(java.lang.String key,
java.lang.String value) |
MapMessage |
with(java.lang.String key,
java.lang.String value)
Add an item to the data Map in fluent style.
|
private static final long serialVersionUID
private final IndexedStringMap data
public MapMessage()
public MapMessage(java.util.Map<java.lang.String,java.lang.String> map)
map
- The Map.public java.lang.String[] getFormats()
MultiformatMessage
getFormats
in interface MultiformatMessage
public java.lang.Object[] getParameters()
getParameters
in interface Message
public java.lang.String getFormat()
public java.util.Map<java.lang.String,java.lang.String> getData()
public IndexedReadOnlyStringMap getIndexedReadOnlyStringMap()
public void clear()
public MapMessage with(java.lang.String key, java.lang.String value)
key
- The name of the data item.value
- The value of the data item.this
public void put(java.lang.String key, java.lang.String value)
key
- The name of the data item.value
- The value of the data item.protected void validate(java.lang.String key, java.lang.String value)
public void putAll(java.util.Map<java.lang.String,java.lang.String> map)
map
- The Map to add.public java.lang.String get(java.lang.String key)
key
- The name of the element.public java.lang.String remove(java.lang.String key)
key
- The name of the element.public java.lang.String asString()
public java.lang.String asString(java.lang.String format)
private java.lang.StringBuilder format(MapMessage.MapFormat format, java.lang.StringBuilder sb)
format
- The format identifier. Ignored in this implementation.public void asXml(java.lang.StringBuilder sb)
public java.lang.String getFormattedMessage()
getFormattedMessage
in interface Message
public java.lang.String getFormattedMessage(java.lang.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(java.lang.StringBuilder sb)
protected void asJson(java.lang.StringBuilder sb)
protected void asJava(java.lang.StringBuilder sb)
public MapMessage newInstance(java.util.Map<java.lang.String,java.lang.String> map)
public java.lang.String toString()
toString
in class java.lang.Object
public void formatTo(java.lang.StringBuilder buffer)
StringBuilderFormattable
StringBuilder
, ideally without allocating
temporary objects.formatTo
in interface StringBuilderFormattable
buffer
- the StringBuilder to write intopublic boolean equals(java.lang.Object o)
equals
in class java.lang.Object
public int hashCode()
hashCode
in class java.lang.Object
public java.lang.Throwable getThrowable()
getThrowable
in interface Message