org.apache.logging.log4j.message

Class MapMessage

  • All Implemented Interfaces:
    Serializable, Message, MultiformatMessage
    Direct Known Subclasses:
    StructuredDataMessage


    public class MapMessage
    extends Object
    implements MultiformatMessage
    Represents a Message that consists of a Map.

    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:
    Serialized Form
    • Constructor Detail

      • MapMessage

        public MapMessage()
        Constructor.
      • MapMessage

        public MapMessage(Map<String,String> map)
        Constructor based on an existing Map.
        Parameters:
        map - The Map.
    • Method Detail

      • getParameters

        public Object[] getParameters()
        Returns the data elements as if they were parameters on the logging event.
        Specified by:
        getParameters in interface Message
        Returns:
        the data elements.
      • getFormat

        public String getFormat()
        Returns the message.
        Specified by:
        getFormat in interface Message
        Returns:
        the message.
      • getData

        public Map<String,String> getData()
        Returns the message data as an unmodifiable Map.
        Returns:
        the message data as an unmodifiable map.
      • clear

        public void clear()
        Clear the data.
      • put

        public void put(String key,
               String value)
        Add an item to the data Map.
        Parameters:
        key - The name of the data item.
        value - The value of the data item.
      • validate

        protected void validate(String key,
                    String value)
      • putAll

        public void putAll(Map<String,String> map)
        Add all the elements from the specified Map.
        Parameters:
        map - The Map to add.
      • get

        public String get(String key)
        Retrieve the value of the element with the specified key or null if the key is not present.
        Parameters:
        key - The name of the element.
        Returns:
        The value of the element or null if the key is not present.
      • remove

        public String remove(String key)
        Remove the element with the specified name.
        Parameters:
        key - The name of the element.
        Returns:
        The previous value of the element.
      • asString

        public String asString()
        Format the Structured data as described in RFC 5424.
        Returns:
        The formatted String.
      • getFormattedMessage

        public String getFormattedMessage()
        Format the message and return it.
        Specified by:
        getFormattedMessage in interface Message
        Returns:
        the formatted message.
      • getFormattedMessage

        public String getFormattedMessage(String[] formats)
        Description copied from interface: MultiformatMessage
        Returns the Message formatted as a String.
        Specified by:
        getFormattedMessage in interface MultiformatMessage
        Parameters:
        formats - An array of Strings that provide extra information about how to format the message. MapMessage uses the first format specifier it recognizes. The supported formats are XML, JSON, and JAVA. The default format is key1="value1" key2="value2" as required by RFC 5424 messages.
        Returns:
        The formatted message.
      • hashCode

        public int hashCode()
        Overrides:
        hashCode in class Object

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.