Class SingleFieldAppendingMarker

java.lang.Object
net.logstash.logback.marker.LogstashMarker
net.logstash.logback.marker.SingleFieldAppendingMarker
All Implemented Interfaces:
Serializable, Iterable<org.slf4j.Marker>, StructuredArgument, org.slf4j.Marker
Direct Known Subclasses:
ObjectAppendingMarker, RawJsonAppendingMarker

public abstract class SingleFieldAppendingMarker extends LogstashMarker implements StructuredArgument
A Marker OR StructuredArgument that appends a single field into the JSON event.

When writing to the JSON data (via ArgumentsJsonProvider or LogstashMarkersJsonProvider):

When writing to a String (when used as a StructuredArgument to the event's formatted message), the messageFormatPattern is used to construct the string output. getFieldName() will be substituted in {0} in the messageFormatPattern. getFieldValue() will be substituted in {1} in the messageFormatPattern. Subclasses must override getFieldValue() to provide the field value to include.

See Also:
  • Field Details

  • Constructor Details

    • SingleFieldAppendingMarker

      public SingleFieldAppendingMarker(String markerName, String fieldName)
    • SingleFieldAppendingMarker

      public SingleFieldAppendingMarker(String markerName, String fieldName, String messageFormatPattern)
  • Method Details

    • getFieldName

      public String getFieldName()
    • writeTo

      public void writeTo(JsonGenerator generator) throws IOException
      Description copied from class: LogstashMarker
      Writes the data associated with this marker to the given JsonGenerator.
      Specified by:
      writeTo in interface StructuredArgument
      Specified by:
      writeTo in class LogstashMarker
      Parameters:
      generator - the generator to which to write the output of this marker.
      Throws:
      IOException - if there was an error writing to the generator
    • writeFieldName

      protected void writeFieldName(JsonGenerator generator) throws IOException
      Writes the field name to the generator.
      Parameters:
      generator - the generator to write JSON
      Throws:
      IOException - if an I/O error occurs
    • writeFieldValue

      protected abstract void writeFieldValue(JsonGenerator generator) throws IOException
      Writes the field value to the generator.
      Parameters:
      generator - the generator to write JSON
      Throws:
      IOException - if an I/O error occurs
    • toStringSelf

      public String toStringSelf()
      Description copied from class: LogstashMarker
      Returns a string representation of this object, without including any references.

      Subclasses should override LogstashMarker.toStringSelf() instead of LogstashMarker.toString(), since LogstashMarker.toString() will automatically include the LogstashMarker.toStringSelf() and references.

      Overrides:
      toStringSelf in class LogstashMarker
      Returns:
      a string representation of this object, without including any references.
    • getFieldValue

      protected abstract Object getFieldValue()
      Return the value that should be included in the output of LogstashMarker.toString().
      Returns:
      the field value
    • equals

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

      public int hashCode()
      Specified by:
      hashCode in interface org.slf4j.Marker
    • 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