Package org.apache.logging.log4j.message
Class StructuredDataMessage
java.lang.Object
org.apache.logging.log4j.message.MapMessage<StructuredDataMessage,String>
org.apache.logging.log4j.message.StructuredDataMessage
- All Implemented Interfaces:
Serializable
,Message
,MultiformatMessage
,MultiFormatStringBuilderFormattable
,StringBuilderFormattable
@AsynchronouslyFormattable
public class StructuredDataMessage
extends MapMessage<StructuredDataMessage,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:
-
Nested Class Summary
Nested ClassesNested classes/interfaces inherited from class org.apache.logging.log4j.message.MapMessage
MapMessage.MapFormat
-
Constructor Summary
ConstructorsModifierConstructorDescriptionprotected
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).Creates a StructuredDataMessage using an ID (max 32 characters), message, type (max 32 characters), and an initial map of structured data to include.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. -
Method Summary
Modifier and TypeMethodDescriptionasString()
Formats the structured data as described in RFC 5424.Formats the structured data as described in RFC 5424.final String
asString
(StructuredDataMessage.Format format, StructuredDataId structuredDataId) Formats the structured data as described in RFC 5424.final void
asString
(StructuredDataMessage.Format format, StructuredDataId structuredDataId, StringBuilder sb) Formats the structured data as described in RFC 5424.boolean
void
formatTo
(String[] formats, StringBuilder buffer) Writes a text representation of this object into the specifiedStringBuilder
, ideally without allocating temporary objects.void
formatTo
(StringBuilder buffer) Writes a text representation of this object into the specifiedStringBuilder
, ideally without allocating temporary objects.Returns the message.String[]
Returns the supported formats.Formats the message and return it.getFormattedMessage
(String[] formats) Formats the message according to the specified format.getId()
Returns this message id.getType()
Returns this message type.int
hashCode()
newInstance
(Map<String, String> map) Constructs a new instance based on an existing Map.protected void
Sets the id from a String.protected void
Sets the id.protected void
setMessageFormat
(String msg) protected void
toString()
protected void
Default implementation does nothing.protected void
Default implementation does nothing.protected void
Default implementation does nothing.protected void
Default implementation does nothing.protected void
Default implementation does nothing.protected void
Default implementation does nothing.protected void
Default implementation does nothing.protected void
Default implementation does nothing.protected void
Default implementation does nothing.protected void
Default implementation does nothing.protected void
validateKey
(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
-
Constructor Details
-
StructuredDataMessage
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
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.0
-
StructuredDataMessage
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(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.- 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.0
-
StructuredDataMessage
Creates a StructuredDataMessage using a StructuredDataId, message, and type (max 32 characters).- Parameters:
id
- The StructuredDataId.msg
- The message.type
- The message type.
-
StructuredDataMessage
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.0
-
StructuredDataMessage
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, 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.- Parameters:
id
- The StructuredDataId.msg
- The message.type
- The message type.data
- The StructuredData map.maxLength
- The maximum length of keys;- Since:
- 2.9.0
-
StructuredDataMessage
protected StructuredDataMessage()Basic constructor.
-
-
Method Details
-
getFormats
Returns the supported formats.- Specified by:
getFormats
in interfaceMultiformatMessage
- Overrides:
getFormats
in classMapMessage<StructuredDataMessage,
String> - Returns:
- An array of the supported format names.
-
getId
Returns this message id.- Returns:
- the StructuredDataId.
-
setId
Sets the id from a String. This ID can be at most 32 characters long.- Parameters:
id
- The String id.
-
setId
Sets the id.- Parameters:
id
- The StructuredDataId.
-
getType
Returns this message type.- Returns:
- the type.
-
setType
-
formatTo
Description copied from interface:StringBuilderFormattable
Writes a text representation of this object into the specifiedStringBuilder
, ideally without allocating temporary objects.- Specified by:
formatTo
in interfaceStringBuilderFormattable
- Overrides:
formatTo
in classMapMessage<StructuredDataMessage,
String> - Parameters:
buffer
- the StringBuilder to write into
-
formatTo
Description copied from interface:MultiFormatStringBuilderFormattable
Writes a text representation of this object into the specifiedStringBuilder
, ideally without allocating temporary objects.- Specified by:
formatTo
in interfaceMultiFormatStringBuilderFormattable
- Overrides:
formatTo
in classMapMessage<StructuredDataMessage,
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
Returns the message.- Specified by:
getFormat
in interfaceMessage
- Overrides:
getFormat
in classMapMessage<StructuredDataMessage,
String> - Returns:
- the message.
-
setMessageFormat
-
asString
Formats the structured data as described in RFC 5424.- Overrides:
asString
in classMapMessage<StructuredDataMessage,
String> - Returns:
- The formatted String.
-
asString
Formats the structured data as described in RFC 5424.- Overrides:
asString
in classMapMessage<StructuredDataMessage,
String> - Parameters:
format
- The format identifier. Ignored in this implementation.- Returns:
- The formatted String.
-
asString
public final 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, 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.- Since:
- 2.8
-
getFormattedMessage
Formats the message and return it.- Specified by:
getFormattedMessage
in interfaceMessage
- Overrides:
getFormattedMessage
in classMapMessage<StructuredDataMessage,
String> - Returns:
- the formatted message.
-
getFormattedMessage
Formats the message according to the specified format.- Specified by:
getFormattedMessage
in interfaceMultiformatMessage
- Overrides:
getFormattedMessage
in classMapMessage<StructuredDataMessage,
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.
-
toString
- Overrides:
toString
in classMapMessage<StructuredDataMessage,
String>
-
newInstance
Description copied from class:MapMessage
Constructs a new instance based on an existing Map.- Overrides:
newInstance
in classMapMessage<StructuredDataMessage,
String> - Parameters:
map
- The Map.- Returns:
- A new MapMessage
-
equals
- Overrides:
equals
in classMapMessage<StructuredDataMessage,
String>
-
hashCode
public int hashCode()- Overrides:
hashCode
in classMapMessage<StructuredDataMessage,
String>
-
validate
Description copied from class:MapMessage
Default implementation does nothing.- Overrides:
validate
in classMapMessage<StructuredDataMessage,
String>
-
validate
Description copied from class:MapMessage
Default implementation does nothing.- Overrides:
validate
in classMapMessage<StructuredDataMessage,
String> - Since:
- 2.9
-
validate
Description copied from class:MapMessage
Default implementation does nothing.- Overrides:
validate
in classMapMessage<StructuredDataMessage,
String> - Since:
- 2.9
-
validate
Description copied from class:MapMessage
Default implementation does nothing.- Overrides:
validate
in classMapMessage<StructuredDataMessage,
String> - Since:
- 2.9
-
validate
Description copied from class:MapMessage
Default implementation does nothing.- Overrides:
validate
in classMapMessage<StructuredDataMessage,
String> - Since:
- 2.9
-
validate
Description copied from class:MapMessage
Default implementation does nothing.- Overrides:
validate
in classMapMessage<StructuredDataMessage,
String> - Since:
- 2.9
-
validate
Description copied from class:MapMessage
Default implementation does nothing.- Overrides:
validate
in classMapMessage<StructuredDataMessage,
String> - Since:
- 2.9
-
validate
Description copied from class:MapMessage
Default implementation does nothing.- Overrides:
validate
in classMapMessage<StructuredDataMessage,
String> - Since:
- 2.9
-
validate
Description copied from class:MapMessage
Default implementation does nothing.- Overrides:
validate
in classMapMessage<StructuredDataMessage,
String> - Since:
- 2.9
-
validate
Description copied from class:MapMessage
Default implementation does nothing.- Overrides:
validate
in classMapMessage<StructuredDataMessage,
String>
-
validateKey
- Since:
- 2.9.0
-