Class ObjectAppendingMarker
- All Implemented Interfaces:
Serializable,Iterable<org.slf4j.Marker>,StructuredArgument,org.slf4j.Marker
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"
}
- See Also:
-
Field Summary
FieldsFields inherited from class net.logstash.logback.marker.SingleFieldAppendingMarker
MARKER_NAME_PREFIXFields inherited from interface org.slf4j.Marker
ANY_MARKER, ANY_NON_NULL_MARKER -
Constructor Summary
ConstructorsConstructorDescriptionObjectAppendingMarker(String fieldName, Object fieldValue) ObjectAppendingMarker(String fieldName, Object fieldValue, String messageFormatPattern) -
Method Summary
Modifier and TypeMethodDescriptionbooleanbooleancontains(org.slf4j.Marker other) booleanprotected ObjectReturn the value that should be included in the output ofLogstashMarker.toString().getName()booleanDeprecated.inthashCode()booleanIterator<org.slf4j.Marker>iterator()booleanremove(org.slf4j.Marker referenceToRemove) protected voidwriteFieldValue(JsonGenerator generator) Writes the field value to the generator.Methods inherited from class net.logstash.logback.marker.SingleFieldAppendingMarker
getFieldName, toStringSelf, writeFieldName, writeToMethods inherited from class net.logstash.logback.marker.LogstashMarker
add, and, toString, withMethods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, waitMethods inherited from interface java.lang.Iterable
forEach, iterator, spliteratorMethods inherited from interface net.logstash.logback.argument.StructuredArgument
toString
-
Field Details
-
MARKER_NAME
- See Also:
-
-
Constructor Details
-
ObjectAppendingMarker
-
ObjectAppendingMarker
-
-
Method Details
-
writeFieldValue
Description copied from class:SingleFieldAppendingMarkerWrites the field value to the generator.- Specified by:
writeFieldValuein classSingleFieldAppendingMarker- Parameters:
generator- the generator to write JSON- Throws:
IOException- if an I/O error occurs
-
getFieldValue
Description copied from class:SingleFieldAppendingMarkerReturn the value that should be included in the output ofLogstashMarker.toString().- Specified by:
getFieldValuein classSingleFieldAppendingMarker- Returns:
- the field value
-
equals
- Specified by:
equalsin interfaceorg.slf4j.Marker- Overrides:
equalsin classSingleFieldAppendingMarker
-
hashCode
public int hashCode()- Specified by:
hashCodein interfaceorg.slf4j.Marker- Overrides:
hashCodein classSingleFieldAppendingMarker
-
getName
- Specified by:
getNamein interfaceorg.slf4j.Marker
-
hasReferences
public boolean hasReferences()- Specified by:
hasReferencesin interfaceorg.slf4j.Marker
-
hasChildren
Deprecated.- Specified by:
hasChildrenin interfaceorg.slf4j.Marker
-
iterator
- Specified by:
iteratorin interfaceorg.slf4j.Marker
-
remove
public boolean remove(org.slf4j.Marker referenceToRemove) - Specified by:
removein interfaceorg.slf4j.Marker
-
contains
public boolean contains(org.slf4j.Marker other) - Specified by:
containsin interfaceorg.slf4j.Marker
-
contains
- Specified by:
containsin interfaceorg.slf4j.Marker
-