Class ObjectAppendingMarker

All Implemented Interfaces:
Serializable, Iterable<org.slf4j.Marker>, StructuredArgument, org.slf4j.Marker

public class ObjectAppendingMarker extends SingleFieldAppendingMarker
A 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 Details

  • Constructor Details

    • ObjectAppendingMarker

      public ObjectAppendingMarker(String fieldName, Object fieldValue)
    • ObjectAppendingMarker

      public ObjectAppendingMarker(String fieldName, Object fieldValue, String messageFormatPattern)
  • Method Details

    • writeFieldValue

      protected void writeFieldValue(JsonGenerator generator) throws IOException
      Description copied from class: SingleFieldAppendingMarker
      Writes the field value to the generator.
      Specified by:
      writeFieldValue in class SingleFieldAppendingMarker
      Parameters:
      generator - the generator to write JSON
      Throws:
      IOException - if an I/O error occurs
    • getFieldValue

      protected Object getFieldValue()
      Description copied from class: SingleFieldAppendingMarker
      Return the value that should be included in the output of LogstashMarker.toString().
      Specified by:
      getFieldValue in class SingleFieldAppendingMarker
      Returns:
      the field value
    • equals

      public boolean equals(Object obj)
      Specified by:
      equals in interface org.slf4j.Marker
      Overrides:
      equals in class SingleFieldAppendingMarker
    • hashCode

      public int hashCode()
      Specified by:
      hashCode in interface org.slf4j.Marker
      Overrides:
      hashCode in class SingleFieldAppendingMarker
    • getName

      public String getName()
      Specified by:
      getName in interface org.slf4j.Marker
    • hasReferences

      public boolean hasReferences()
      Specified by:
      hasReferences in interface org.slf4j.Marker
    • hasChildren

      @Deprecated public boolean hasChildren()
      Deprecated.
      Specified by:
      hasChildren in interface org.slf4j.Marker
    • iterator

      public Iterator<org.slf4j.Marker> iterator()
      Specified by:
      iterator in interface org.slf4j.Marker
    • remove

      public boolean remove(org.slf4j.Marker referenceToRemove)
      Specified by:
      remove in interface org.slf4j.Marker
    • contains

      public boolean contains(org.slf4j.Marker other)
      Specified by:
      contains in interface org.slf4j.Marker
    • contains

      public boolean contains(String name)
      Specified by:
      contains in interface org.slf4j.Marker