Package org.apache.logging.log4j.message
Class StructuredDataMessage
- java.lang.Object
-
- org.apache.logging.log4j.message.MapMessage<StructuredDataMessage,java.lang.String>
-
- org.apache.logging.log4j.message.StructuredDataMessage
-
- All Implemented Interfaces:
java.io.Serializable,Message,MultiformatMessage,MultiFormatStringBuilderFormattable,StringBuilderFormattable
@AsynchronouslyFormattable public class StructuredDataMessage extends MapMessage<StructuredDataMessage,java.lang.String>
Represents a Message that conforms to an RFC 5424 StructuredData element along with the syslog message.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.
- See Also:
- RFC 5424, Serialized Form
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classStructuredDataMessage.FormatSupported formats.-
Nested classes/interfaces inherited from class org.apache.logging.log4j.message.MapMessage
MapMessage.MapFormat
-
-
Field Summary
Fields Modifier and Type Field Description private static intHASHVALprivate StructuredDataIdidprivate static intMAX_LENGTHprivate intmaxLengthprivate java.lang.Stringmessageprivate static longserialVersionUIDprivate java.lang.Stringtype
-
Constructor Summary
Constructors Modifier Constructor Description protectedStructuredDataMessage()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, int maxLength)Creates a StructuredDataMessage using an ID (user specified max characters), message, and type (user specified maximum number of 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(java.lang.String id, java.lang.String msg, java.lang.String type, java.util.Map<java.lang.String,java.lang.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, 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, int maxLength)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.StructuredDataMessage(StructuredDataId id, java.lang.String msg, java.lang.String type, java.util.Map<java.lang.String,java.lang.String> data, int maxLength)Creates a StructuredDataMessage using a StructuredDataId, message, type (max 32 characters), and an initial map of structured data to include.privateStructuredDataMessage(StructuredDataMessage msg, java.util.Map<java.lang.String,java.lang.String> map)Constructor based on a StructuredDataMessage.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description java.lang.StringasString()Formats the structured data as described in RFC 5424.java.lang.StringasString(java.lang.String format)Formats the structured data as described in RFC 5424.java.lang.StringasString(StructuredDataMessage.Format format, StructuredDataId structuredDataId)Formats the structured data as described in RFC 5424.voidasString(StructuredDataMessage.Format format, StructuredDataId structuredDataId, java.lang.StringBuilder sb)Formats the structured data as described in RFC 5424.private voidasXml(StructuredDataId structuredDataId, java.lang.StringBuilder sb)booleanequals(java.lang.Object o)voidformatTo(java.lang.String[] formats, java.lang.StringBuilder buffer)Writes a text representation of this object into the specifiedStringBuilder, ideally without allocating temporary objects.voidformatTo(java.lang.StringBuilder buffer)Writes a text representation of this object into the specifiedStringBuilder, ideally without allocating temporary objects.java.lang.StringgetFormat()Returns the message.private StructuredDataMessage.FormatgetFormat(java.lang.String[] formats)java.lang.String[]getFormats()Returns the supported formats.java.lang.StringgetFormattedMessage()Formats the message and return it.java.lang.StringgetFormattedMessage(java.lang.String[] formats)Formats the message according to the specified format.StructuredDataIdgetId()Returns this message id.java.lang.StringgetType()Returns this message type.inthashCode()StructuredDataMessagenewInstance(java.util.Map<java.lang.String,java.lang.String> map)Constructs a new instance based on an existing Map.protected voidsetId(java.lang.String id)Sets the id from a String.protected voidsetId(StructuredDataId id)Sets the id.protected voidsetMessageFormat(java.lang.String msg)protected voidsetType(java.lang.String type)java.lang.StringtoString()protected voidvalidate(java.lang.String key, boolean value)Default implementation does nothing.protected voidvalidate(java.lang.String key, byte value)Default implementation does nothing.protected voidvalidate(java.lang.String key, char value)Default implementation does nothing.protected voidvalidate(java.lang.String key, double value)Default implementation does nothing.protected voidvalidate(java.lang.String key, float value)Default implementation does nothing.protected voidvalidate(java.lang.String key, int value)Default implementation does nothing.protected voidvalidate(java.lang.String key, long value)Default implementation does nothing.protected voidvalidate(java.lang.String key, short value)Default implementation does nothing.protected voidvalidate(java.lang.String key, java.lang.Object value)Default implementation does nothing.protected voidvalidate(java.lang.String key, java.lang.String value)Default implementation does nothing.protected voidvalidateKey(java.lang.String key)-
Methods inherited from class org.apache.logging.log4j.message.MapMessage
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
-
-
-
-
Field Detail
-
serialVersionUID
private static final long serialVersionUID
- See Also:
- Constant Field Values
-
MAX_LENGTH
private static final int MAX_LENGTH
- See Also:
- Constant Field Values
-
HASHVAL
private static final int HASHVAL
- See Also:
- Constant Field Values
-
id
private StructuredDataId id
-
message
private java.lang.String message
-
type
private java.lang.String type
-
maxLength
private final int maxLength
-
-
Constructor Detail
-
StructuredDataMessage
public 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).- Parameters:
id- The String id.msg- The message.type- The message type.
-
StructuredDataMessage
public StructuredDataMessage(java.lang.String id, java.lang.String msg, java.lang.String type, int maxLength)Creates a StructuredDataMessage using an ID (user specified max characters), message, and type (user specified maximum number of characters).- Parameters:
id- The String id.msg- The message.type- The message type.maxLength- The maximum length of keys;- Since:
- 2.9
-
StructuredDataMessage
public 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.- Parameters:
id- The String id.msg- The message.type- The message type.data- The StructuredData map.
-
StructuredDataMessage
public StructuredDataMessage(java.lang.String id, java.lang.String msg, java.lang.String type, java.util.Map<java.lang.String,java.lang.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.- Parameters:
id- The String id.msg- The message.type- The message type.data- The StructuredData map.maxLength- The maximum length of keys;- Since:
- 2.9
-
StructuredDataMessage
public StructuredDataMessage(StructuredDataId id, java.lang.String msg, java.lang.String type)
Creates a StructuredDataMessage using a StructuredDataId, message, and type (max 32 characters).- Parameters:
id- The StructuredDataId.msg- The message.type- The message type.
-
StructuredDataMessage
public StructuredDataMessage(StructuredDataId id, java.lang.String msg, java.lang.String type, int maxLength)
Creates a StructuredDataMessage using a StructuredDataId, message, and type (max 32 characters).- Parameters:
id- The StructuredDataId.msg- The message.type- The message type.maxLength- The maximum length of keys;- Since:
- 2.9
-
StructuredDataMessage
public 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.- Parameters:
id- The StructuredDataId.msg- The message.type- The message type.data- The StructuredData map.
-
StructuredDataMessage
public StructuredDataMessage(StructuredDataId id, java.lang.String msg, java.lang.String type, java.util.Map<java.lang.String,java.lang.String> data, int maxLength)
Creates a StructuredDataMessage using a StructuredDataId, message, type (max 32 characters), and an initial map of structured data to include.- Parameters:
id- The StructuredDataId.msg- The message.type- The message type.data- The StructuredData map.maxLength- The maximum length of keys;- Since:
- 2.9
-
StructuredDataMessage
private StructuredDataMessage(StructuredDataMessage msg, java.util.Map<java.lang.String,java.lang.String> map)
Constructor based on a StructuredDataMessage.- Parameters:
msg- The StructuredDataMessage.map- The StructuredData map.
-
StructuredDataMessage
protected StructuredDataMessage()
Basic constructor.
-
-
Method Detail
-
getFormats
public java.lang.String[] getFormats()
Returns the supported formats.- Specified by:
getFormatsin interfaceMultiformatMessage- Overrides:
getFormatsin classMapMessage<StructuredDataMessage,java.lang.String>- Returns:
- An array of the supported format names.
-
getId
public StructuredDataId getId()
Returns this message id.- Returns:
- the StructuredDataId.
-
setId
protected void setId(java.lang.String id)
Sets the id from a String. This ID can be at most 32 characters long.- Parameters:
id- The String id.
-
setId
protected void setId(StructuredDataId id)
Sets the id.- Parameters:
id- The StructuredDataId.
-
getType
public java.lang.String getType()
Returns this message type.- Returns:
- the type.
-
setType
protected void setType(java.lang.String type)
-
formatTo
public void formatTo(java.lang.StringBuilder buffer)
Description copied from interface:StringBuilderFormattableWrites a text representation of this object into the specifiedStringBuilder, ideally without allocating temporary objects.- Specified by:
formatToin interfaceStringBuilderFormattable- Overrides:
formatToin classMapMessage<StructuredDataMessage,java.lang.String>- Parameters:
buffer- the StringBuilder to write into
-
formatTo
public void formatTo(java.lang.String[] formats, java.lang.StringBuilder buffer)Description copied from interface:MultiFormatStringBuilderFormattableWrites a text representation of this object into the specifiedStringBuilder, ideally without allocating temporary objects.- Specified by:
formatToin interfaceMultiFormatStringBuilderFormattable- Overrides:
formatToin classMapMessage<StructuredDataMessage,java.lang.String>- Parameters:
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 into
-
getFormat
public java.lang.String getFormat()
Returns the message.- Specified by:
getFormatin interfaceMessage- Overrides:
getFormatin classMapMessage<StructuredDataMessage,java.lang.String>- Returns:
- the message.
-
setMessageFormat
protected void setMessageFormat(java.lang.String msg)
-
asString
public java.lang.String asString()
Formats the structured data as described in RFC 5424.- Overrides:
asStringin classMapMessage<StructuredDataMessage,java.lang.String>- Returns:
- The formatted String.
-
asString
public java.lang.String asString(java.lang.String format)
Formats the structured data as described in RFC 5424.- Overrides:
asStringin classMapMessage<StructuredDataMessage,java.lang.String>- Parameters:
format- The format identifier. Ignored in this implementation.- Returns:
- The formatted String.
-
asString
public final java.lang.String asString(StructuredDataMessage.Format format, StructuredDataId structuredDataId)
Formats the structured data as described in RFC 5424.- Parameters:
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.- Returns:
- The formatted String.
-
asString
public final void asString(StructuredDataMessage.Format format, StructuredDataId structuredDataId, java.lang.StringBuilder sb)
Formats the structured data as described in RFC 5424.- Parameters:
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.
-
asXml
private void asXml(StructuredDataId structuredDataId, java.lang.StringBuilder sb)
-
getFormattedMessage
public java.lang.String getFormattedMessage()
Formats the message and return it.- Specified by:
getFormattedMessagein interfaceMessage- Overrides:
getFormattedMessagein classMapMessage<StructuredDataMessage,java.lang.String>- Returns:
- the formatted message.
-
getFormattedMessage
public java.lang.String getFormattedMessage(java.lang.String[] formats)
Formats the message according to the specified format.- Specified by:
getFormattedMessagein interfaceMultiformatMessage- Overrides:
getFormattedMessagein classMapMessage<StructuredDataMessage,java.lang.String>- Parameters:
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".- Returns:
- the formatted message.
-
getFormat
private StructuredDataMessage.Format getFormat(java.lang.String[] formats)
-
toString
public java.lang.String toString()
- Overrides:
toStringin classMapMessage<StructuredDataMessage,java.lang.String>
-
newInstance
public StructuredDataMessage newInstance(java.util.Map<java.lang.String,java.lang.String> map)
Description copied from class:MapMessageConstructs a new instance based on an existing Map.- Overrides:
newInstancein classMapMessage<StructuredDataMessage,java.lang.String>- Parameters:
map- The Map.- Returns:
- A new MapMessage
-
equals
public boolean equals(java.lang.Object o)
- Overrides:
equalsin classMapMessage<StructuredDataMessage,java.lang.String>
-
hashCode
public int hashCode()
- Overrides:
hashCodein classMapMessage<StructuredDataMessage,java.lang.String>
-
validate
protected void validate(java.lang.String key, boolean value)Description copied from class:MapMessageDefault implementation does nothing.- Overrides:
validatein classMapMessage<StructuredDataMessage,java.lang.String>
-
validate
protected void validate(java.lang.String key, byte value)Description copied from class:MapMessageDefault implementation does nothing.- Overrides:
validatein classMapMessage<StructuredDataMessage,java.lang.String>- Since:
- 2.9
-
validate
protected void validate(java.lang.String key, char value)Description copied from class:MapMessageDefault implementation does nothing.- Overrides:
validatein classMapMessage<StructuredDataMessage,java.lang.String>- Since:
- 2.9
-
validate
protected void validate(java.lang.String key, double value)Description copied from class:MapMessageDefault implementation does nothing.- Overrides:
validatein classMapMessage<StructuredDataMessage,java.lang.String>- Since:
- 2.9
-
validate
protected void validate(java.lang.String key, float value)Description copied from class:MapMessageDefault implementation does nothing.- Overrides:
validatein classMapMessage<StructuredDataMessage,java.lang.String>- Since:
- 2.9
-
validate
protected void validate(java.lang.String key, int value)Description copied from class:MapMessageDefault implementation does nothing.- Overrides:
validatein classMapMessage<StructuredDataMessage,java.lang.String>- Since:
- 2.9
-
validate
protected void validate(java.lang.String key, long value)Description copied from class:MapMessageDefault implementation does nothing.- Overrides:
validatein classMapMessage<StructuredDataMessage,java.lang.String>- Since:
- 2.9
-
validate
protected void validate(java.lang.String key, java.lang.Object value)Description copied from class:MapMessageDefault implementation does nothing.- Overrides:
validatein classMapMessage<StructuredDataMessage,java.lang.String>- Since:
- 2.9
-
validate
protected void validate(java.lang.String key, short value)Description copied from class:MapMessageDefault implementation does nothing.- Overrides:
validatein classMapMessage<StructuredDataMessage,java.lang.String>- Since:
- 2.9
-
validate
protected void validate(java.lang.String key, java.lang.String value)Description copied from class:MapMessageDefault implementation does nothing.- Overrides:
validatein classMapMessage<StructuredDataMessage,java.lang.String>
-
validateKey
protected void validateKey(java.lang.String key)
-
-