@AsynchronouslyFormattable public class StructuredDataMessage extends MapMessage implements 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 |
StructuredDataMessage.Format
Supported formats.
|
MapMessage.MapFormat
Modifier and Type | Field and Description |
---|---|
private static int |
HASHVAL |
private StructuredDataId |
id |
private static int |
MAX_LENGTH |
private java.lang.String |
message |
private static long |
serialVersionUID |
private java.lang.String |
type |
Modifier | Constructor and Description |
---|---|
protected |
StructuredDataMessage()
Basic constructor.
|
|
StructuredDataMessage(java.lang.String id,
java.lang.String msg,
java.lang.String type)
Creates a StructuredDataMessage using an ID (max 32 characters), message, and type (max 32 characters).
|
|
StructuredDataMessage(java.lang.String id,
java.lang.String msg,
java.lang.String type,
java.util.Map<java.lang.String,java.lang.String> data)
Creates a StructuredDataMessage using an ID (max 32 characters), message, type (max 32 characters), and an
initial map of structured data to include.
|
|
StructuredDataMessage(StructuredDataId id,
java.lang.String msg,
java.lang.String type)
Creates a StructuredDataMessage using a StructuredDataId, message, and type (max 32 characters).
|
|
StructuredDataMessage(StructuredDataId id,
java.lang.String msg,
java.lang.String type,
java.util.Map<java.lang.String,java.lang.String> data)
Creates a StructuredDataMessage using a StructuredDataId, message, type (max 32 characters), and an initial map
of structured data to include.
|
private |
StructuredDataMessage(StructuredDataMessage msg,
java.util.Map<java.lang.String,java.lang.String> map)
Constructor based on a StructuredDataMessage.
|
Modifier and Type | Method and Description |
---|---|
java.lang.String |
asString()
Formats the structured data as described in RFC 5424.
|
java.lang.String |
asString(java.lang.String format)
Formats the structured data as described in RFC 5424.
|
java.lang.String |
asString(StructuredDataMessage.Format format,
StructuredDataId structuredDataId)
Formats the structured data as described in RFC 5424.
|
void |
asString(StructuredDataMessage.Format format,
StructuredDataId structuredDataId,
java.lang.StringBuilder sb)
Formats the structured data as described in RFC 5424.
|
private java.lang.String |
asXml() |
boolean |
equals(java.lang.Object o) |
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 |
getFormat()
Returns the message.
|
java.lang.String[] |
getFormats()
Returns the supported formats.
|
java.lang.String |
getFormattedMessage()
Formats the message and return it.
|
java.lang.String |
getFormattedMessage(java.lang.String[] formats)
Formats the message according the the specified format.
|
StructuredDataId |
getId()
Returns this message id.
|
java.lang.String |
getType()
Returns this message type.
|
int |
hashCode() |
MapMessage |
newInstance(java.util.Map<java.lang.String,java.lang.String> map) |
protected void |
setId(java.lang.String id)
Sets the id from a String.
|
protected void |
setId(StructuredDataId id)
Sets the id.
|
protected void |
setMessageFormat(java.lang.String msg) |
protected void |
setType(java.lang.String type) |
java.lang.String |
toString() |
protected void |
validate(java.lang.String key,
java.lang.String value) |
private void |
validateKey(java.lang.String key) |
StructuredDataMessage |
with(java.lang.String key,
java.lang.String value)
Add an item to the data Map in fluent style.
|
appendMap, asJava, asJson, asXml, clear, get, getData, getIndexedReadOnlyStringMap, getParameters, getThrowable, put, putAll, remove
private static final long serialVersionUID
private static final int MAX_LENGTH
private static final int HASHVAL
private StructuredDataId id
private java.lang.String message
private java.lang.String type
public StructuredDataMessage(java.lang.String id, java.lang.String msg, java.lang.String type)
id
- The String id.msg
- The message.type
- The message type.public StructuredDataMessage(java.lang.String id, java.lang.String msg, java.lang.String type, java.util.Map<java.lang.String,java.lang.String> data)
id
- The String id.msg
- The message.type
- The message type.data
- The StructuredData map.public StructuredDataMessage(StructuredDataId id, java.lang.String msg, java.lang.String type)
id
- The StructuredDataId.msg
- The message.type
- The message type.public StructuredDataMessage(StructuredDataId id, java.lang.String msg, java.lang.String type, java.util.Map<java.lang.String,java.lang.String> data)
id
- The StructuredDataId.msg
- The message.type
- The message type.data
- The StructuredData map.private StructuredDataMessage(StructuredDataMessage msg, java.util.Map<java.lang.String,java.lang.String> map)
msg
- The StructuredDataMessage.map
- The StructuredData map.protected StructuredDataMessage()
public StructuredDataMessage with(java.lang.String key, java.lang.String value)
with
in class MapMessage
key
- The name of the data item.value
- The value of the data item.this
public java.lang.String[] getFormats()
getFormats
in interface MultiformatMessage
getFormats
in class MapMessage
public StructuredDataId getId()
protected void setId(java.lang.String id)
id
- The String id.protected void setId(StructuredDataId id)
id
- The StructuredDataId.public java.lang.String getType()
protected void setType(java.lang.String type)
public void formatTo(java.lang.StringBuilder buffer)
StringBuilderFormattable
StringBuilder
, ideally without allocating
temporary objects.formatTo
in interface StringBuilderFormattable
formatTo
in class MapMessage
buffer
- the StringBuilder to write intopublic java.lang.String getFormat()
getFormat
in interface Message
getFormat
in class MapMessage
protected void setMessageFormat(java.lang.String msg)
protected void validate(java.lang.String key, java.lang.String value)
validate
in class MapMessage
private void validateKey(java.lang.String key)
public java.lang.String asString()
asString
in class MapMessage
public java.lang.String asString(java.lang.String format)
asString
in class MapMessage
format
- The format identifier. Ignored in this implementation.public final java.lang.String asString(StructuredDataMessage.Format format, StructuredDataId structuredDataId)
format
- "full" will include the type and message. null will return only the STRUCTURED-DATA as
described in RFC 5424structuredDataId
- The SD-ID as described in RFC 5424. If null the value in the StructuredData
will be used.public final void asString(StructuredDataMessage.Format format, StructuredDataId structuredDataId, java.lang.StringBuilder sb)
format
- "full" will include the type and message. null will return only the STRUCTURED-DATA as
described in RFC 5424structuredDataId
- The SD-ID as described in RFC 5424. If null the value in the StructuredData
will be used.sb
- The StringBuilder to append the formatted message to.public java.lang.String getFormattedMessage()
getFormattedMessage
in interface Message
getFormattedMessage
in class MapMessage
public java.lang.String getFormattedMessage(java.lang.String[] formats)
getFormattedMessage
in interface MultiformatMessage
getFormattedMessage
in class MapMessage
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".private java.lang.String asXml()
public java.lang.String toString()
toString
in class MapMessage
public MapMessage newInstance(java.util.Map<java.lang.String,java.lang.String> map)
newInstance
in class MapMessage
public boolean equals(java.lang.Object o)
equals
in class MapMessage
public int hashCode()
hashCode
in class MapMessage