Class LogstashMarker

java.lang.Object
net.logstash.logback.marker.LogstashMarker
All Implemented Interfaces:
Serializable, Iterable<org.slf4j.Marker>, org.slf4j.Marker
Direct Known Subclasses:
DeferredLogstashMarker, EmptyLogstashMarker, MapEntriesAppendingMarker, ObjectFieldsAppendingMarker, SingleFieldAppendingMarker

public abstract class LogstashMarker extends Object implements Iterable<org.slf4j.Marker>
A Marker that is known and understood by the logstash logback encoder.

In particular these markers are used to write data into the logstash json event via writeTo(JsonGenerator).

See Also:
  • Field Details

  • Constructor Details

    • LogstashMarker

      public LogstashMarker(String name)
  • Method Details

    • and

      public <T extends LogstashMarker> T and(org.slf4j.Marker reference)
      Adds the given marker as a reference, and returns this marker.

      This can be used to chain markers together fluently on a log line. For example:

       
       import static net.logstash.logback.marker.Markers.*
      
       logger.info(append("name1", "value1).and(append("name2", "value2")), "log message");
       
       
      Type Parameters:
      T - subtype of LogstashMarker
      Parameters:
      reference - The marker to add
      Returns:
      A marker with this marker and the given marker
    • with

      @Deprecated public <T extends LogstashMarker> T with(org.slf4j.Marker reference)
      Deprecated.
      Use and(Marker) instead
      Type Parameters:
      T - subtype of LogstashMarker
      Parameters:
      reference - The marker to add
      Returns:
      A marker with this marker and the given marker
      See Also:
    • writeTo

      public abstract void writeTo(JsonGenerator generator) throws IOException
      Writes the data associated with this marker to the given JsonGenerator.
      Parameters:
      generator - the generator to which to write the output of this marker.
      Throws:
      IOException - if there was an error writing to the generator
    • add

      public void add(org.slf4j.Marker reference)
      Specified by:
      add in interface org.slf4j.Marker
    • toString

      public String toString()
      Returns a String in the form of
           self, reference1, reference2, ...
       

      Where self is the value returned by toStringSelf(), and reference* are the toString() values of any references.

      It is recommended that subclasses only override toStringSelf(), so that references are automatically included in the value returned from toString().

      Returns:
      a string representation of the object, which includes references
    • toStringSelf

      protected String toStringSelf()
      Returns a string representation of this object, without including any references.

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

      Returns:
      a string representation of this object, without including any references.
    • 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
    • equals

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

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