org.apache.logging.log4j.message

Class StructuredDataMessage

  • All Implemented Interfaces:
    Serializable, Message, MultiformatMessage


    public class StructuredDataMessage
    extends MapMessage
    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 Detail

      • StructuredDataMessage

        public StructuredDataMessage(String id,
                             String msg,
                             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(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.
        Parameters:
        id - The String id.
        msg - The message.
        type - The message type.
        data - The StructuredData map.
      • StructuredDataMessage

        public StructuredDataMessage(StructuredDataId id,
                             String msg,
                             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,
                             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.
        Parameters:
        id - The StructuredDataId.
        msg - The message.
        type - The message type.
        data - The StructuredData map.
      • StructuredDataMessage

        protected StructuredDataMessage()
        Basic constructor.
    • Method Detail

      • getId

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

        protected void setId(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 String getType()
        Returns this message type.
        Returns:
        the type.
      • setType

        protected void setType(String type)
      • setMessageFormat

        protected void setMessageFormat(String msg)
      • asString

        public String asString()
        Formats the structured data as described in RFC 5424.
        Overrides:
        asString in class MapMessage
        Returns:
        The formatted String.
      • asString

        public String asString(String format)
        Formats the structured data as described in RFC 5424.
        Overrides:
        asString in class MapMessage
        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 5424
        structuredDataId - The SD-ID as described in RFC 5424. If null the value in the StructuredData will be used.
        Returns:
        The formatted String.
      • getFormattedMessage

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

Copyright © 1999-2015 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.