Top Description Inners Fields Constructors Methods
org.apache.logging.log4j.message

public Class StructuredDataMessage

extends MapMessage<StructuredDataMessage, String>
Class Inheritance
Annotations
@AsynchronouslyFormattable
Imports
java.util.Map, org.apache.logging.log4j.util.EnglishEnums, .StringBuilders

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

Nested and Inner Type Summary

Modifier and TypeClass and Description
public static enum
StructuredDataMessage.Format

Supported formats.

Field Summary

Modifier and TypeField and Description
private static final int
private StructuredDataId
private static final int
private final int
private String
private static final long
private String

Constructor Summary

AccessConstructor and Description
public
StructuredDataMessage(final String
The String id.
id
,
final String
The message.
msg
,
final String
The message type.
type
)

Creates a StructuredDataMessage using an ID (max 32 characters), message, and type (max 32 characters).

public
StructuredDataMessage(final String
The String id.
id
,
final String
The message.
msg
,
final String
The message type.
type
,
final int
The maximum length of keys;
maxLength
)

Creates a StructuredDataMessage using an ID (user specified max characters), message, and type (user specified maximum number of characters).

public
StructuredDataMessage(final String
The String id.
id
,
final String
The message.
msg
,
final String
The message type.
type
,
final Map<String, String>
The StructuredData map.
data
)

Creates a StructuredDataMessage using an ID (max 32 characters), message, type (max 32 characters), and an initial map of structured data to include.

public
StructuredDataMessage(final String
The String id.
id
,
final String
The message.
msg
,
final String
The message type.
type
,
final Map<String, String>
The StructuredData map.
data
,
final int
The maximum length of keys;
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.

public
StructuredDataMessage(final StructuredDataId
The StructuredDataId.
id
,
final String
The message.
msg
,
final String
The message type.
type
)

Creates a StructuredDataMessage using a StructuredDataId, message, and type (max 32 characters).

public
StructuredDataMessage(final StructuredDataId
The StructuredDataId.
id
,
final String
The message.
msg
,
final String
The message type.
type
,
final int
The maximum length of keys;
maxLength
)

Creates a StructuredDataMessage using a StructuredDataId, message, and type (max 32 characters).

public
StructuredDataMessage(final StructuredDataId
The StructuredDataId.
id
,
final String
The message.
msg
,
final String
The message type.
type
,
final Map<String, String>
The StructuredData map.
data
)

Creates a StructuredDataMessage using a StructuredDataId, message, type (max 32 characters), and an initial map of structured data to include.

public
StructuredDataMessage(final StructuredDataId
The StructuredDataId.
id
,
final String
The message.
msg
,
final String
The message type.
type
,
final Map<String, String>
The StructuredData map.
data
,
final int
The maximum length of keys;
maxLength
)

Creates a StructuredDataMessage using a StructuredDataId, message, type (max 32 characters), and an initial map of structured data to include.

private
StructuredDataMessage(final StructuredDataMessage
The StructuredDataMessage.
msg
,
final Map<String, String>
The StructuredData map.
map
)

Constructor based on a StructuredDataMessage.

protected
StructuredDataMessage()

Basic constructor.

Method Summary

Modifier and TypeMethod and Description
public String

Returns:

The formatted String.
asString
()

Overrides org.apache.logging.log4j.message.MapMessage.asString.

Formats the structured data as described in RFC 5424.

public String

Returns:

The formatted String.
asString
(final String
The format identifier. Ignored in this implementation.
format
)

Overrides org.apache.logging.log4j.message.MapMessage.asString.

Formats the structured data as described in RFC 5424.

public final String

Returns:

The formatted String.
asString
(final StructuredDataMessage.Format
"full" will include the type and message. null will return only the STRUCTURED-DATA as described in RFC 5424
format
,
final StructuredDataId
The SD-ID as described in RFC 5424. If null the value in the StructuredData will be used.
structuredDataId
)

Formats the structured data as described in RFC 5424.

public final void
asString(final StructuredDataMessage.Format
"full" will include the type and message. null will return only the STRUCTURED-DATA as described in RFC 5424
format
,
final StructuredDataId
The SD-ID as described in RFC 5424. If null the value in the StructuredData will be used.
structuredDataId
,
final StringBuilder
The StringBuilder to append the formatted message to.
sb
)

Formats the structured data as described in RFC 5424.

private void
asXml(final StructuredDataId structuredDataId, final StringBuilder sb)

public boolean
equals(final Object
the reference object with which to compare.
o
)

Overrides org.apache.logging.log4j.message.MapMessage.equals.

Indicates whether some other object is "equal to" this one.

public void
formatTo(final StringBuilder
the StringBuilder to write into
buffer
)

Overrides org.apache.logging.log4j.message.MapMessage.formatTo.

Implements org.apache.logging.log4j.util.StringBuilderFormattable.formatTo.

Writes a text representation of this object into the specified StringBuilder, ideally without allocating temporary objects.

public void
formatTo(final String[]
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.
formats
,
final StringBuilder
the StringBuilder to write into
buffer
)

Overrides org.apache.logging.log4j.message.MapMessage.formatTo.

Implements org.apache.logging.log4j.util.MultiFormatStringBuilderFormattable.formatTo.

Writes a text representation of this object into the specified StringBuilder, ideally without allocating temporary objects.

public String
private StructuredDataMessage.Format
public String[]

Returns:

An array of the supported format names.
getFormats
()

Overrides org.apache.logging.log4j.message.MapMessage.getFormats.

Implements org.apache.logging.log4j.message.MultiformatMessage.getFormats.

Returns the supported formats.

public String
public String

Returns:

the formatted message.
getFormattedMessage
(final String[]
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".
formats
)

Overrides org.apache.logging.log4j.message.MapMessage.getFormattedMessage.

Implements org.apache.logging.log4j.message.MultiformatMessage.getFormattedMessage.

Formats the message according to the specified format.

public StructuredDataId

Returns:

the StructuredDataId.
getId
()

Returns this message id.

public String

Returns:

the type.
getType
()

Returns this message type.

public int
hashCode()

Overrides org.apache.logging.log4j.message.MapMessage.hashCode.

Returns a hash code value for this object.

public StructuredDataMessage
newInstance(final Map<String, String>
The Map.
map
)

Overrides org.apache.logging.log4j.message.MapMessage.newInstance.

Constructs a new instance based on an existing Map.

protected void
setId(final String
The String id.
id
)

Sets the id from a String.

protected void
setId(final StructuredDataId
The StructuredDataId.
id
)

Sets the id.

protected void
protected void
setType(final String type)

public String
toString()

Overrides org.apache.logging.log4j.message.MapMessage.toString.

Returns a string representation of the object.

protected void
validate(final String key, final boolean value)

Overrides org.apache.logging.log4j.message.MapMessage.validate.

Default implementation does nothing.

protected void
validate(final String key, final byte value)

Overrides org.apache.logging.log4j.message.MapMessage.validate.

Default implementation does nothing.

protected void
validate(final String key, final char value)

Overrides org.apache.logging.log4j.message.MapMessage.validate.

Default implementation does nothing.

protected void
validate(final String key, final double value)

Overrides org.apache.logging.log4j.message.MapMessage.validate.

Default implementation does nothing.

protected void
validate(final String key, final float value)

Overrides org.apache.logging.log4j.message.MapMessage.validate.

Default implementation does nothing.

protected void
validate(final String key, final int value)

Overrides org.apache.logging.log4j.message.MapMessage.validate.

Default implementation does nothing.

protected void
validate(final String key, final long value)

Overrides org.apache.logging.log4j.message.MapMessage.validate.

Default implementation does nothing.

protected void
validate(final String key, final Object value)

Overrides org.apache.logging.log4j.message.MapMessage.validate.

Default implementation does nothing.

protected void
validate(final String key, final short value)

Overrides org.apache.logging.log4j.message.MapMessage.validate.

Default implementation does nothing.

protected void
validate(final String key, final String value)

Overrides org.apache.logging.log4j.message.MapMessage.validate.

Default implementation does nothing.

protected void
validateKey(final String key)

Inherited from org.apache.logging.log4j.message.MapMessage:
appendMapasJavaasJavaUnquotedasJsonasXmlclearcontainsKeyforEachforEachgetgetDatagetIndexedReadOnlyStringMapgetParametersgetThrowableputputAllremovetoKeywithwithwithwithwithwithwithwithwithwith

Field Detail

HASHVALback to summary
private static final int HASHVAL
idback to summary
private StructuredDataId id
MAX_LENGTHback to summary
private static final int MAX_LENGTH
maxLengthback to summary
private final int maxLength
messageback to summary
private String message
serialVersionUIDback to summary
private static final long serialVersionUID

Hides org.apache.logging.log4j.message.MapMessage.serialVersionUID.

typeback to summary
private String type

Constructor Detail

StructuredDataMessageback to summary
public StructuredDataMessage(final String id, final String msg, final String type)

Creates a StructuredDataMessage using an ID (max 32 characters), message, and type (max 32 characters).

Parameters
id:String

The String id.

msg:String

The message.

type:String

The message type.

StructuredDataMessageback to summary
public StructuredDataMessage(final String id, final String msg, final String type, final int maxLength)

Creates a StructuredDataMessage using an ID (user specified max characters), message, and type (user specified maximum number of characters).

Parameters
id:String

The String id.

msg:String

The message.

type:String

The message type.

maxLength:int

The maximum length of keys;

Since
2.9
StructuredDataMessageback to summary
public StructuredDataMessage(final String id, final String msg, final String type, final 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:String

The String id.

msg:String

The message.

type:String

The message type.

data:Map<String, String>

The StructuredData map.

StructuredDataMessageback to summary
public StructuredDataMessage(final String id, final String msg, final String type, final Map<String, String> data, final 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:String

The String id.

msg:String

The message.

type:String

The message type.

data:Map<String, String>

The StructuredData map.

maxLength:int

The maximum length of keys;

Since
2.9
StructuredDataMessageback to summary
public StructuredDataMessage(final StructuredDataId id, final String msg, final String type)

Creates a StructuredDataMessage using a StructuredDataId, message, and type (max 32 characters).

Parameters
id:StructuredDataId

The StructuredDataId.

msg:String

The message.

type:String

The message type.

StructuredDataMessageback to summary
public StructuredDataMessage(final StructuredDataId id, final String msg, final String type, final int maxLength)

Creates a StructuredDataMessage using a StructuredDataId, message, and type (max 32 characters).

Parameters
id:StructuredDataId

The StructuredDataId.

msg:String

The message.

type:String

The message type.

maxLength:int

The maximum length of keys;

Since
2.9
StructuredDataMessageback to summary
public StructuredDataMessage(final StructuredDataId id, final String msg, final String type, final 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:StructuredDataId

The StructuredDataId.

msg:String

The message.

type:String

The message type.

data:Map<String, String>

The StructuredData map.

StructuredDataMessageback to summary
public StructuredDataMessage(final StructuredDataId id, final String msg, final String type, final Map<String, String> data, final int maxLength)

Creates a StructuredDataMessage using a StructuredDataId, message, type (max 32 characters), and an initial map of structured data to include.

Parameters
id:StructuredDataId

The StructuredDataId.

msg:String

The message.

type:String

The message type.

data:Map<String, String>

The StructuredData map.

maxLength:int

The maximum length of keys;

Since
2.9
StructuredDataMessageback to summary
private StructuredDataMessage(final StructuredDataMessage msg, final Map<String, String> map)

Constructor based on a StructuredDataMessage.

Parameters
msg:StructuredDataMessage

The StructuredDataMessage.

map:Map<String, String>

The StructuredData map.

StructuredDataMessageback to summary
protected StructuredDataMessage()

Basic constructor.

Method Detail

asStringback to summary
public String asString()

Overrides org.apache.logging.log4j.message.MapMessage.asString.

Formats the structured data as described in RFC 5424.

Returns:String

The formatted String.

Annotations
@Override
asStringback to summary
public String asString(final String format)

Overrides org.apache.logging.log4j.message.MapMessage.asString.

Formats the structured data as described in RFC 5424.

Parameters
format:String

The format identifier. Ignored in this implementation.

Returns:String

The formatted String.

Annotations
@Override
asStringback to summary
public final String asString(final StructuredDataMessage.Format format, final StructuredDataId structuredDataId)

Formats the structured data as described in RFC 5424.

Parameters
format:StructuredDataMessage.Format

"full" will include the type and message. null will return only the STRUCTURED-DATA as described in RFC 5424

structuredDataId:StructuredDataId

The SD-ID as described in RFC 5424. If null the value in the StructuredData will be used.

Returns:String

The formatted String.

asStringback to summary
public final void asString(final StructuredDataMessage.Format format, final StructuredDataId structuredDataId, final StringBuilder sb)

Formats the structured data as described in RFC 5424.

Parameters
format:StructuredDataMessage.Format

"full" will include the type and message. null will return only the STRUCTURED-DATA as described in RFC 5424

structuredDataId:StructuredDataId

The SD-ID as described in RFC 5424. If null the value in the StructuredData will be used.

sb:StringBuilder

The StringBuilder to append the formatted message to.

asXmlback to summary
private void asXml(final StructuredDataId structuredDataId, final StringBuilder sb)
equalsback to summary
public boolean equals(final Object o)

Overrides org.apache.logging.log4j.message.MapMessage.equals.

Doc from java.lang.Object.equals.

Indicates whether some other object is "equal to" this one.

The equals method implements an equivalence relation on non-null object references:

  • It is reflexive: for any non-null reference value x, x.equals(x) should return true.
  • It is symmetric: for any non-null reference values x and y, x.equals(y) should return true if and only if y.equals(x) returns true.
  • It is transitive: for any non-null reference values x, y, and z, if x.equals(y) returns true and y.equals(z) returns true, then x.equals(z) should return true.
  • It is consistent: for any non-null reference values x and y, multiple invocations of x.equals(y) consistently return true or consistently return false, provided no information used in equals comparisons on the objects is modified.
  • For any non-null reference value x, x.equals(null) should return false.

An equivalence relation partitions the elements it operates on into equivalence classes; all the members of an equivalence class are equal to each other. Members of an equivalence class are substitutable for each other, at least for some purposes.

Parameters
o:Object

the reference object with which to compare.

Returns:boolean

true if this object is the same as the obj argument; false otherwise.

Annotations
@Override
formatToback to summary
public void formatTo(final StringBuilder buffer)

Overrides org.apache.logging.log4j.message.MapMessage.formatTo.

Implements org.apache.logging.log4j.util.StringBuilderFormattable.formatTo.

Doc from org.apache.logging.log4j.util.StringBuilderFormattable.formatTo.

Writes a text representation of this object into the specified StringBuilder, ideally without allocating temporary objects.

Parameters
buffer:StringBuilder

the StringBuilder to write into

Annotations
@Override
formatToback to summary
public void formatTo(final String[] formats, final StringBuilder buffer)

Overrides org.apache.logging.log4j.message.MapMessage.formatTo.

Implements org.apache.logging.log4j.util.MultiFormatStringBuilderFormattable.formatTo.

Doc from org.apache.logging.log4j.util.MultiFormatStringBuilderFormattable.formatTo.

Writes a text representation of this object into the specified StringBuilder, ideally without allocating temporary objects.

Parameters
formats:String[]

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:StringBuilder

the StringBuilder to write into

Annotations
@Override
getFormatback to summary
public String getFormat()

Overrides org.apache.logging.log4j.message.MapMessage.getFormat.

Implements org.apache.logging.log4j.message.Message.getFormat.

Returns the message.

Returns:String

the message.

Annotations
@Override
getFormatback to summary
private StructuredDataMessage.Format getFormat(final String[] formats)

Hides org.apache.logging.log4j.message.MapMessage.getFormat.

getFormatsback to summary
public String[] getFormats()

Overrides org.apache.logging.log4j.message.MapMessage.getFormats.

Implements org.apache.logging.log4j.message.MultiformatMessage.getFormats.

Returns the supported formats.

Returns:String[]

An array of the supported format names.

Annotations
@Override
getFormattedMessageback to summary
public String getFormattedMessage()

Overrides org.apache.logging.log4j.message.MapMessage.getFormattedMessage.

Implements org.apache.logging.log4j.message.Message.getFormattedMessage.

Formats the message and return it.

Returns:String

the formatted message.

Annotations
@Override
getFormattedMessageback to summary
public String getFormattedMessage(final String[] formats)

Overrides org.apache.logging.log4j.message.MapMessage.getFormattedMessage.

Implements org.apache.logging.log4j.message.MultiformatMessage.getFormattedMessage.

Formats the message according to the specified format.

Parameters
formats:String[]

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:String

the formatted message.

Annotations
@Override
getIdback to summary
public StructuredDataId getId()

Returns this message id.

Returns:StructuredDataId

the StructuredDataId.

getTypeback to summary
public String getType()

Returns this message type.

Returns:String

the type.

hashCodeback to summary
public int hashCode()

Overrides org.apache.logging.log4j.message.MapMessage.hashCode.

Doc from java.lang.Object.hashCode.

Returns a hash code value for this object. This method is supported for the benefit of hash tables such as those provided by java.util.HashMap.

The general contract of hashCode is:

  • Whenever it is invoked on the same object more than once during an execution of a Java application, the hashCode method must consistently return the same integer, provided no information used in equals comparisons on the object is modified. This integer need not remain consistent from one execution of an application to another execution of the same application.
  • If two objects are equal according to the equals method, then calling the hashCode method on each of the two objects must produce the same integer result.
  • It is not required that if two objects are unequal according to the equals method, then calling the hashCode method on each of the two objects must produce distinct integer results. However, the programmer should be aware that producing distinct integer results for unequal objects may improve the performance of hash tables.
Returns:int

a hash code value for this object

Annotations
@Override
newInstanceback to summary
public StructuredDataMessage newInstance(final Map<String, String> map)

Overrides org.apache.logging.log4j.message.MapMessage.newInstance.

Doc from org.apache.logging.log4j.message.MapMessage.newInstance.

Constructs a new instance based on an existing Map.

Parameters
map:Map<String, String>

The Map.

Returns:StructuredDataMessage

A new MapMessage

Annotations
@Override
setIdback to summary
protected void setId(final String id)

Sets the id from a String. This ID can be at most 32 characters long.

Parameters
id:String

The String id.

setIdback to summary
protected void setId(final StructuredDataId id)

Sets the id.

Parameters
id:StructuredDataId

The StructuredDataId.

setMessageFormatback to summary
protected void setMessageFormat(final String msg)
setTypeback to summary
protected void setType(final String type)
toStringback to summary
public String toString()

Overrides org.apache.logging.log4j.message.MapMessage.toString.

Doc from java.lang.Object.toString.

Returns a string representation of the object. Satisfying this method's contract implies a non-null result must be returned.

Returns:String

a string representation of the object

Annotations
@Override
validateback to summary
protected void validate(final String key, final boolean value)

Overrides org.apache.logging.log4j.message.MapMessage.validate.

Doc from org.apache.logging.log4j.message.MapMessage.validate.

Default implementation does nothing.

Annotations
@Override
validateback to summary
protected void validate(final String key, final byte value)

Overrides org.apache.logging.log4j.message.MapMessage.validate.

Doc from org.apache.logging.log4j.message.MapMessage.validate.

Default implementation does nothing.

Annotations
@Override
Since
2.9
validateback to summary
protected void validate(final String key, final char value)

Overrides org.apache.logging.log4j.message.MapMessage.validate.

Doc from org.apache.logging.log4j.message.MapMessage.validate.

Default implementation does nothing.

Annotations
@Override
Since
2.9
validateback to summary
protected void validate(final String key, final double value)

Overrides org.apache.logging.log4j.message.MapMessage.validate.

Doc from org.apache.logging.log4j.message.MapMessage.validate.

Default implementation does nothing.

Annotations
@Override
Since
2.9
validateback to summary
protected void validate(final String key, final float value)

Overrides org.apache.logging.log4j.message.MapMessage.validate.

Doc from org.apache.logging.log4j.message.MapMessage.validate.

Default implementation does nothing.

Annotations
@Override
Since
2.9
validateback to summary
protected void validate(final String key, final int value)

Overrides org.apache.logging.log4j.message.MapMessage.validate.

Doc from org.apache.logging.log4j.message.MapMessage.validate.

Default implementation does nothing.

Annotations
@Override
Since
2.9
validateback to summary
protected void validate(final String key, final long value)

Overrides org.apache.logging.log4j.message.MapMessage.validate.

Doc from org.apache.logging.log4j.message.MapMessage.validate.

Default implementation does nothing.

Annotations
@Override
Since
2.9
validateback to summary
protected void validate(final String key, final Object value)

Overrides org.apache.logging.log4j.message.MapMessage.validate.

Doc from org.apache.logging.log4j.message.MapMessage.validate.

Default implementation does nothing.

Annotations
@Override
Since
2.9
validateback to summary
protected void validate(final String key, final short value)

Overrides org.apache.logging.log4j.message.MapMessage.validate.

Doc from org.apache.logging.log4j.message.MapMessage.validate.

Default implementation does nothing.

Annotations
@Override
Since
2.9
validateback to summary
protected void validate(final String key, final String value)

Overrides org.apache.logging.log4j.message.MapMessage.validate.

Doc from org.apache.logging.log4j.message.MapMessage.validate.

Default implementation does nothing.

Annotations
@Override
validateKeyback to summary
protected void validateKey(final String key)
org.apache.logging.log4j.message back to summary

public final Enum StructuredDataMessage.Format

extends Enum<StructuredDataMessage.Format>
Class Inheritance

Supported formats.

Field Summary

Modifier and TypeField and Description
public static final StructuredDataMessage.Format
FULL

Full message format includes the type and message.

public static final StructuredDataMessage.Format
XML

The map should be formatted as XML.

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
public static StructuredDataMessage.Format
public static StructuredDataMessage.Format[]
Inherited from java.lang.Enum:
clonecompareTodescribeConstableequalsfinalizegetDeclaringClasshashCodenameordinaltoStringvalueOf

Field Detail

FULLback to summary
public static final StructuredDataMessage.Format FULL

Full message format includes the type and message.

XMLback to summary
public static final StructuredDataMessage.Format XML

The map should be formatted as XML.

Constructor Detail

Formatback to summary
private Format()

Method Detail

valueOfback to summary
public static StructuredDataMessage.Format valueOf(String name)
valuesback to summary
public static StructuredDataMessage.Format[] values()