public class ObjectAppendingMarker extends SingleFieldAppendingMarker
Marker OR StructuredArgument that
writes an object under a given fieldName in the log event output.
When writing to the JSON data (via ArgumentsJsonProvider or LogstashMarkersJsonProvider),
the object will be converted into an appropriate JSON type
(number, string, object, array) and written to the JSON event under a given fieldName.
When writing to a String (when used as a StructuredArgument to the event's formatted message),
as specified in SingleFieldAppendingMarker, the SingleFieldAppendingMarker.messageFormatPattern
is used to construct the string to include in the event's formatted message.
StructuredArguments.toString(Object) will be used to convert the value to a string,
prior to being substituted into the messageFormatPattern.
An ObjectMapper is used to convert/write the value when writing to JSON,
so as long as the ObjectMapper can convert the object, you're good.
For example, to append a string field, use a String object as the object.
To append a numeric field, use a Number object as the object.
To append an array field, use an array as the object.
To append an object field, use some other Object as the object.
Example:
logger.info("My Message {}", StructuredArguments.keyValue("key", "value"));
results in the following log event output:
{
"message" : "My Message key=value",
"key" : "value"
}
| Modifier and Type | Field and Description |
|---|---|
static String |
MARKER_NAME |
MARKER_NAME_PREFIX| Constructor and Description |
|---|
ObjectAppendingMarker(String fieldName,
Object fieldValue) |
ObjectAppendingMarker(String fieldName,
Object fieldValue,
String messageFormatPattern) |
| Modifier and Type | Method and Description |
|---|---|
boolean |
contains(org.slf4j.Marker other) |
boolean |
contains(String name) |
boolean |
equals(Object obj) |
Object |
getFieldValue()
Return the value that should be included in the output of
LogstashMarker.toString(). |
String |
getName() |
boolean |
hasChildren()
Deprecated.
|
int |
hashCode() |
boolean |
hasReferences() |
Iterator<org.slf4j.Marker> |
iterator() |
boolean |
remove(org.slf4j.Marker referenceToRemove) |
protected void |
writeFieldValue(JsonGenerator generator)
Writes the field value to the generator.
|
getFieldName, toStringSelf, writeFieldName, writeToadd, and, toString, withclone, finalize, getClass, notify, notifyAll, toString, wait, wait, waittoStringforEach, iterator, spliteratorpublic static final String MARKER_NAME
protected void writeFieldValue(JsonGenerator generator) throws IOException
SingleFieldAppendingMarkerwriteFieldValue in class SingleFieldAppendingMarkergenerator - the generator to write JSONIOException - if an I/O error occurspublic Object getFieldValue()
SingleFieldAppendingMarkerLogstashMarker.toString().getFieldValue in class SingleFieldAppendingMarkerpublic boolean equals(Object obj)
equals in interface org.slf4j.Markerequals in class SingleFieldAppendingMarkerpublic int hashCode()
hashCode in interface org.slf4j.MarkerhashCode in class SingleFieldAppendingMarkerpublic String getName()
getName in interface org.slf4j.Markerpublic boolean hasReferences()
hasReferences in interface org.slf4j.Marker@Deprecated public boolean hasChildren()
hasChildren in interface org.slf4j.Markerpublic Iterator<org.slf4j.Marker> iterator()
iterator in interface org.slf4j.Markerpublic boolean remove(org.slf4j.Marker referenceToRemove)
remove in interface org.slf4j.Markerpublic boolean contains(org.slf4j.Marker other)
contains in interface org.slf4j.Markerpublic boolean contains(String name)
contains in interface org.slf4j.MarkerCopyright © 2013–2021. All rights reserved.