Class StructuredDataMessage

  • All Implemented Interfaces:
    java.io.Serializable, Message, MultiformatMessage, org.apache.logging.log4j.util.MultiFormatStringBuilderFormattable, org.apache.logging.log4j.util.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
    • Constructor Summary

      Constructors 
      Constructor Description
      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.
    • 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
    • Method Detail

      • getId

        public StructuredDataId getId()
        Returns this message id.
        Returns:
        the StructuredDataId.
      • getType

        public java.lang.String getType()
        Returns this message type.
        Returns:
        the type.
      • formatTo

        public void formatTo​(java.lang.StringBuilder buffer)
        Specified by:
        formatTo in interface org.apache.logging.log4j.util.StringBuilderFormattable
        Overrides:
        formatTo in class MapMessage<StructuredDataMessage,​java.lang.String>
      • formatTo

        public void formatTo​(java.lang.String[] formats,
                             java.lang.StringBuilder buffer)
        Specified by:
        formatTo in interface org.apache.logging.log4j.util.MultiFormatStringBuilderFormattable
        Overrides:
        formatTo in class MapMessage<StructuredDataMessage,​java.lang.String>
      • asString

        public java.lang.String asString()
        Formats the structured data as described in RFC 5424.
        Overrides:
        asString in class MapMessage<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:
        asString in class MapMessage<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 5424
        structuredDataId - 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 5424
        structuredDataId - 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.
      • getFormattedMessage

        public java.lang.String getFormattedMessage​(java.lang.String[] formats)
        Formats the message according to the specified format.
        Specified by:
        getFormattedMessage in interface MultiformatMessage
        Overrides:
        getFormattedMessage in class MapMessage<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.