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
ConstructorsModifierConstructorDescriptionprotectedBasic 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 StringasString(StructuredDataMessage.Format format, StructuredDataId structuredDataId) Formats the structured data as described in RFC 5424.final voidasString(StructuredDataMessage.Format format, StructuredDataId structuredDataId, StringBuilder sb) Formats the structured data as described in RFC 5424.booleanvoidformatTo(String[] formats, StringBuilder buffer) Writes a text representation of this object into the specifiedStringBuilder, ideally without allocating temporary objects.voidformatTo(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.inthashCode()newInstance(Map<String, String> map) Constructs a new instance based on an existing Map.protected voidSets the id from a String.protected voidSets the id.protected voidsetMessageFormat(String msg) protected voidtoString()protected voidDefault implementation does nothing.protected voidDefault implementation does nothing.protected voidDefault implementation does nothing.protected voidDefault implementation does nothing.protected voidDefault implementation does nothing.protected voidDefault implementation does nothing.protected voidDefault implementation does nothing.protected voidDefault implementation does nothing.protected voidDefault implementation does nothing.protected voidDefault implementation does nothing.protected voidvalidateKey(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:
getFormatsin interfaceMultiformatMessage- Overrides:
getFormatsin 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:StringBuilderFormattableWrites a text representation of this object into the specifiedStringBuilder, ideally without allocating temporary objects.- Specified by:
formatToin interfaceStringBuilderFormattable- Overrides:
formatToin classMapMessage<StructuredDataMessage,String> - Parameters:
buffer- the StringBuilder to write into
-
formatTo
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,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:
getFormatin interfaceMessage- Overrides:
getFormatin classMapMessage<StructuredDataMessage,String> - Returns:
- the message.
-
setMessageFormat
-
asString
Formats the structured data as described in RFC 5424.- Overrides:
asStringin classMapMessage<StructuredDataMessage,String> - Returns:
- The formatted String.
-
asString
Formats the structured data as described in RFC 5424.- Overrides:
asStringin 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:
getFormattedMessagein interfaceMessage- Overrides:
getFormattedMessagein classMapMessage<StructuredDataMessage,String> - Returns:
- the formatted message.
-
getFormattedMessage
Formats the message according to the specified format.- Specified by:
getFormattedMessagein interfaceMultiformatMessage- Overrides:
getFormattedMessagein 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:
toStringin classMapMessage<StructuredDataMessage,String>
-
newInstance
Description copied from class:MapMessageConstructs a new instance based on an existing Map.- Overrides:
newInstancein classMapMessage<StructuredDataMessage,String> - Parameters:
map- The Map.- Returns:
- A new MapMessage
-
equals
- Overrides:
equalsin classMapMessage<StructuredDataMessage,String>
-
hashCode
public int hashCode()- Overrides:
hashCodein classMapMessage<StructuredDataMessage,String>
-
validate
Description copied from class:MapMessageDefault implementation does nothing.- Overrides:
validatein classMapMessage<StructuredDataMessage,String>
-
validate
Description copied from class:MapMessageDefault implementation does nothing.- Overrides:
validatein classMapMessage<StructuredDataMessage,String> - Since:
- 2.9
-
validate
Description copied from class:MapMessageDefault implementation does nothing.- Overrides:
validatein classMapMessage<StructuredDataMessage,String> - Since:
- 2.9
-
validate
Description copied from class:MapMessageDefault implementation does nothing.- Overrides:
validatein classMapMessage<StructuredDataMessage,String> - Since:
- 2.9
-
validate
Description copied from class:MapMessageDefault implementation does nothing.- Overrides:
validatein classMapMessage<StructuredDataMessage,String> - Since:
- 2.9
-
validate
Description copied from class:MapMessageDefault implementation does nothing.- Overrides:
validatein classMapMessage<StructuredDataMessage,String> - Since:
- 2.9
-
validate
Description copied from class:MapMessageDefault implementation does nothing.- Overrides:
validatein classMapMessage<StructuredDataMessage,String> - Since:
- 2.9
-
validate
Description copied from class:MapMessageDefault implementation does nothing.- Overrides:
validatein classMapMessage<StructuredDataMessage,String> - Since:
- 2.9
-
validate
Description copied from class:MapMessageDefault implementation does nothing.- Overrides:
validatein classMapMessage<StructuredDataMessage,String> - Since:
- 2.9
-
validate
Description copied from class:MapMessageDefault implementation does nothing.- Overrides:
validatein classMapMessage<StructuredDataMessage,String>
-
validateKey
- Since:
- 2.9.0
-