@AsynchronouslyFormattable public class StructuredDataMessage extends MapMessage<StructuredDataMessage,String>
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 | Constructor and Description |
---|---|
protected |
StructuredDataMessage()
Basic constructor.
|
|
StructuredDataMessage(String id,
String msg,
String type)
Creates a StructuredDataMessage using an ID (max 32 characters), message, and type (max 32 characters).
|
|
StructuredDataMessage(String id,
String msg,
String type,
int maxLength)
Creates a StructuredDataMessage using an ID (user specified max characters), message, and type (user specified
maximum number of characters).
|
|
StructuredDataMessage(String id,
String msg,
String type,
Map<String,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(String id,
String msg,
String type,
Map<String,String> data,
int maxLength)
Creates a StructuredDataMessage using an (user specified max characters), message, and type (user specified
maximum number of characters, and an initial map of structured data to include.
|
|
StructuredDataMessage(StructuredDataId id,
String msg,
String type)
Creates a StructuredDataMessage using a StructuredDataId, message, and type (max 32 characters).
|
|
StructuredDataMessage(StructuredDataId id,
String msg,
String type,
int maxLength)
Creates a StructuredDataMessage using a StructuredDataId, message, and type (max 32 characters).
|
|
StructuredDataMessage(StructuredDataId id,
String msg,
String type,
Map<String,String> data)
Creates a StructuredDataMessage using a StructuredDataId, message, type (max 32 characters), and an initial map
of structured data to include.
|
|
StructuredDataMessage(StructuredDataId id,
String msg,
String type,
Map<String,String> data,
int maxLength)
Creates a StructuredDataMessage using a StructuredDataId, message, type (max 32 characters), and an initial map
of structured data to include.
|
Modifier and Type | Method and Description |
---|---|
String |
asString()
Formats the structured data as described in RFC 5424.
|
String |
asString(String format)
Formats the structured data as described in RFC 5424.
|
String |
asString(StructuredDataMessage.Format format,
StructuredDataId structuredDataId)
Formats the structured data as described in RFC 5424.
|
void |
asString(StructuredDataMessage.Format format,
StructuredDataId structuredDataId,
StringBuilder sb)
Formats the structured data as described in RFC 5424.
|
boolean |
equals(Object o) |
void |
formatTo(String[] formats,
StringBuilder buffer)
Writes a text representation of this object into the specified
StringBuilder , ideally without allocating
temporary objects. |
void |
formatTo(StringBuilder buffer)
Writes a text representation of this object into the specified
StringBuilder , ideally without allocating
temporary objects. |
String |
getFormat()
Returns the message.
|
String[] |
getFormats()
Returns the supported formats.
|
String |
getFormattedMessage()
Formats the message and return it.
|
String |
getFormattedMessage(String[] formats)
Formats the message according to the specified format.
|
StructuredDataId |
getId()
Returns this message id.
|
String |
getType()
Returns this message type.
|
int |
hashCode() |
StructuredDataMessage |
newInstance(Map<String,String> map)
Constructs a new instance based on an existing Map.
|
protected void |
setId(String id)
Sets the id from a String.
|
protected void |
setId(StructuredDataId id)
Sets the id.
|
protected void |
setMessageFormat(String msg) |
protected void |
setType(String type) |
String |
toString() |
protected void |
validate(String key,
boolean value)
Default implementation does nothing.
|
protected void |
validate(String key,
byte value)
Default implementation does nothing.
|
protected void |
validate(String key,
char value)
Default implementation does nothing.
|
protected void |
validate(String key,
double value)
Default implementation does nothing.
|
protected void |
validate(String key,
float value)
Default implementation does nothing.
|
protected void |
validate(String key,
int value)
Default implementation does nothing.
|
protected void |
validate(String key,
long value)
Default implementation does nothing.
|
protected void |
validate(String key,
Object value)
Default implementation does nothing.
|
protected void |
validate(String key,
short value)
Default implementation does nothing.
|
protected void |
validate(String key,
String value)
Default implementation does nothing.
|
protected void |
validateKey(String key) |
appendMap, asJava, asJavaUnquoted, asJson, asXml, clear, containsKey, forEach, forEach, get, getData, getIndexedReadOnlyStringMap, getParameters, getThrowable, put, putAll, remove, toKey, with, with, with, with, with, with, with, with, with, with
public StructuredDataMessage(String id, String msg, String type)
id
- The String id.msg
- The message.type
- The message type.public StructuredDataMessage(String id, String msg, String type, int maxLength)
id
- The String id.msg
- The message.type
- The message type.maxLength
- The maximum length of keys;public StructuredDataMessage(String id, String msg, String type, Map<String,String> data)
id
- The String id.msg
- The message.type
- The message type.data
- The StructuredData map.public StructuredDataMessage(String id, String msg, String type, Map<String,String> data, int maxLength)
id
- The String id.msg
- The message.type
- The message type.data
- The StructuredData map.maxLength
- The maximum length of keys;public StructuredDataMessage(StructuredDataId id, String msg, String type)
id
- The StructuredDataId.msg
- The message.type
- The message type.public StructuredDataMessage(StructuredDataId id, String msg, String type, int maxLength)
id
- The StructuredDataId.msg
- The message.type
- The message type.maxLength
- The maximum length of keys;public StructuredDataMessage(StructuredDataId id, String msg, String type, Map<String,String> data)
id
- The StructuredDataId.msg
- The message.type
- The message type.data
- The StructuredData map.public StructuredDataMessage(StructuredDataId id, String msg, String type, Map<String,String> data, int maxLength)
id
- The StructuredDataId.msg
- The message.type
- The message type.data
- The StructuredData map.maxLength
- The maximum length of keys;protected StructuredDataMessage()
public String[] getFormats()
getFormats
in interface MultiformatMessage
getFormats
in class MapMessage<StructuredDataMessage,String>
public StructuredDataId getId()
protected void setId(String id)
id
- The String id.protected void setId(StructuredDataId id)
id
- The StructuredDataId.public void formatTo(StringBuilder buffer)
StringBuilderFormattable
StringBuilder
, ideally without allocating
temporary objects.formatTo
in interface StringBuilderFormattable
formatTo
in class MapMessage<StructuredDataMessage,String>
buffer
- the StringBuilder to write intopublic void formatTo(String[] formats, StringBuilder buffer)
MultiFormatStringBuilderFormattable
StringBuilder
, ideally without allocating
temporary objects.formatTo
in interface MultiFormatStringBuilderFormattable
formatTo
in class MapMessage<StructuredDataMessage,String>
formats
- An array of Strings that provide extra information about how to format the message.
Each MultiFormatStringBuilderFormattable implementation is free to use the provided formats however they choose.buffer
- the StringBuilder to write intopublic String getFormat()
getFormat
in interface Message
getFormat
in class MapMessage<StructuredDataMessage,String>
protected void setMessageFormat(String msg)
public String asString()
asString
in class MapMessage<StructuredDataMessage,String>
public String asString(String format)
asString
in class MapMessage<StructuredDataMessage,String>
format
- The format identifier. Ignored in this implementation.public final 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, 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 String getFormattedMessage()
getFormattedMessage
in interface Message
getFormattedMessage
in class MapMessage<StructuredDataMessage,String>
public String getFormattedMessage(String[] formats)
getFormattedMessage
in interface MultiformatMessage
getFormattedMessage
in class MapMessage<StructuredDataMessage,String>
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".public String toString()
toString
in class MapMessage<StructuredDataMessage,String>
public StructuredDataMessage newInstance(Map<String,String> map)
MapMessage
newInstance
in class MapMessage<StructuredDataMessage,String>
map
- The Map.public boolean equals(Object o)
equals
in class MapMessage<StructuredDataMessage,String>
public int hashCode()
hashCode
in class MapMessage<StructuredDataMessage,String>
protected void validate(String key, boolean value)
MapMessage
validate
in class MapMessage<StructuredDataMessage,String>
protected void validate(String key, byte value)
MapMessage
validate
in class MapMessage<StructuredDataMessage,String>
protected void validate(String key, char value)
MapMessage
validate
in class MapMessage<StructuredDataMessage,String>
protected void validate(String key, double value)
MapMessage
validate
in class MapMessage<StructuredDataMessage,String>
protected void validate(String key, float value)
MapMessage
validate
in class MapMessage<StructuredDataMessage,String>
protected void validate(String key, int value)
MapMessage
validate
in class MapMessage<StructuredDataMessage,String>
protected void validate(String key, long value)
MapMessage
validate
in class MapMessage<StructuredDataMessage,String>
protected void validate(String key, Object value)
MapMessage
validate
in class MapMessage<StructuredDataMessage,String>
protected void validate(String key, short value)
MapMessage
validate
in class MapMessage<StructuredDataMessage,String>
protected void validate(String key, String value)
MapMessage
validate
in class MapMessage<StructuredDataMessage,String>
protected void validateKey(String key)
Copyright © 1999-1969 The 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.