Overview | Package | Class | Use | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

## org.apache.logging.log4j.message
Class MapMessage

    java.lang.Object
      org.apache.logging.log4j.message.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

Nested Class Summary
`static class` | `MapMessage.MapFormat` When set as the format specifier causes the Map to be formatted as XML.

Constructor Summary
`MapMessage()` Constructor.
`MapMessage(Map<String,String> map)` Constructor based on an existing Map.

Method Summary
`protected void` | `appendMap(StringBuilder sb)`
`protected void` | `asJava(StringBuilder sb)`
`protected void` | `asJson(StringBuilder sb)`
`String` | `asString()` Format the Structured data as described in RFC 5424.
`String` | `asString(String format)`
`void` | `asXml(StringBuilder sb)`
`void` | `clear()` Clear the data.
`boolean` | `equals(Object o)`
`String` | `get(String key)` Retrieve the value of the element with the specified key or null if the key is not present.
`Map<String,String>` | `getData()` Returns the message data as an unmodifiable Map.
`String` | `getFormat()` Returns the message.
`String[]` | `getFormats()` Returns the supported formats.
`String` | `getFormattedMessage()` Format the message and return it.
`String` | `getFormattedMessage(String[] formats)` Returns the Message formatted as a String.
`Object[]` | `getParameters()` Returns the data elements as if they were parameters on the logging event.
`Throwable` | `getThrowable()` Always returns null.
`int` | `hashCode()`
`MapMessage` | `newInstance(Map<String,String> map)`
`void` | `put(String key, String value)` Add an item to the data Map.
`void` | `putAll(Map<String,String> map)` Add all the elements from the specified Map.
`String` | `remove(String key)` Remove the element with the specified name.
`String` | `toString()`
`protected void` | `validate(String key, String value)`

Methods inherited from class java.lang.Object
`clone, finalize, getClass, notify, notifyAll, wait, wait, wait`

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

### getFormats

    public String[] getFormats()

  Description copied from interface: `MultiformatMessage`
  Returns the supported formats.

  Specified by:
    `getFormats` in interface `MultiformatMessage`
  Returns:
    The supported formats.

### 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.

### asString

    public String asString(String format)

### asXml

    public void asXml(StringBuilder sb)

### 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.

### appendMap

    protected void appendMap(StringBuilder sb)

### asJson

    protected void asJson(StringBuilder sb)

### asJava

    protected void asJava(StringBuilder sb)

### newInstance

    public MapMessage newInstance(Map<String,String> map)

### toString

    public String toString()

  Overrides:
    `toString` in class `Object`

### equals

    public boolean equals(Object o)

  Overrides:
    `equals` in class `Object`

### hashCode

    public int hashCode()

  Overrides:
    `hashCode` in class `Object`

### getThrowable

    public Throwable getThrowable()

  Always returns null.

  Specified by:
    `getThrowable` in interface `Message`
  Returns:
    null

Overview | Package | Class | Use | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

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.