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 object) |
ObjectAppendingMarker(String fieldName,
Object object,
String messageFormatPattern) |
Modifier and Type | Method and Description |
---|---|
boolean |
equals(Object obj) |
Object |
getFieldValue()
Return the value that should be included in the output of
LogstashMarker.toString() . |
int |
hashCode() |
protected void |
writeFieldValue(JsonGenerator generator)
Writes the field value to the generator.
|
getFieldName, toStringSelf, writeFieldName, writeTo
and, toString, with
add, contains, contains, getName, hasChildren, hasReferences, iterator, remove
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
toString
forEach, iterator, spliterator
public static final String MARKER_NAME
protected void writeFieldValue(JsonGenerator generator) throws IOException
SingleFieldAppendingMarker
writeFieldValue
in class SingleFieldAppendingMarker
IOException
public Object getFieldValue()
SingleFieldAppendingMarker
LogstashMarker.toString()
.getFieldValue
in class SingleFieldAppendingMarker
public boolean equals(Object obj)
equals
in interface org.slf4j.Marker
equals
in class SingleFieldAppendingMarker
public int hashCode()
hashCode
in interface org.slf4j.Marker
hashCode
in class SingleFieldAppendingMarker
Copyright © 2020. All rights reserved.