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
Fields inherited from class net.logstash.logback.marker.SingleFieldAppendingMarker
MARKER_NAME_PREFIX
Fields inherited from interface org.slf4j.Marker
ANY_MARKER, ANY_NON_NULL_MARKER
-
Constructor Summary
ConstructorDescriptionObjectAppendingMarker
(String fieldName, Object fieldValue) ObjectAppendingMarker
(String fieldName, Object fieldValue, String messageFormatPattern) -
Method Summary
Modifier and TypeMethodDescriptionboolean
boolean
contains
(org.slf4j.Marker other) boolean
protected Object
Return the value that should be included in the output ofLogstashMarker.toString()
.getName()
boolean
Deprecated.int
hashCode()
boolean
Iterator<org.slf4j.Marker>
iterator()
boolean
remove
(org.slf4j.Marker referenceToRemove) protected void
writeFieldValue
(JsonGenerator generator) Writes the field value to the generator.Methods inherited from class net.logstash.logback.marker.SingleFieldAppendingMarker
getFieldName, toStringSelf, writeFieldName, writeTo
Methods inherited from class net.logstash.logback.marker.LogstashMarker
add, and, toString, with
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
Methods inherited from interface java.lang.Iterable
forEach, iterator, spliterator
Methods 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:SingleFieldAppendingMarker
Writes the field value to the generator.- Specified by:
writeFieldValue
in classSingleFieldAppendingMarker
- Parameters:
generator
- the generator to write JSON- Throws:
IOException
- if an I/O error occurs
-
getFieldValue
Description copied from class:SingleFieldAppendingMarker
Return the value that should be included in the output ofLogstashMarker.toString()
.- Specified by:
getFieldValue
in classSingleFieldAppendingMarker
- Returns:
- the field value
-
equals
- Specified by:
equals
in interfaceorg.slf4j.Marker
- Overrides:
equals
in classSingleFieldAppendingMarker
-
hashCode
public int hashCode()- Specified by:
hashCode
in interfaceorg.slf4j.Marker
- Overrides:
hashCode
in classSingleFieldAppendingMarker
-
getName
- Specified by:
getName
in interfaceorg.slf4j.Marker
-
hasReferences
public boolean hasReferences()- Specified by:
hasReferences
in interfaceorg.slf4j.Marker
-
hasChildren
Deprecated.- Specified by:
hasChildren
in interfaceorg.slf4j.Marker
-
iterator
- Specified by:
iterator
in interfaceorg.slf4j.Marker
-
remove
public boolean remove(org.slf4j.Marker referenceToRemove) - Specified by:
remove
in interfaceorg.slf4j.Marker
-
contains
public boolean contains(org.slf4j.Marker other) - Specified by:
contains
in interfaceorg.slf4j.Marker
-
contains
- Specified by:
contains
in interfaceorg.slf4j.Marker
-