Class ESJsonLayout

java.lang.Object
org.apache.logging.log4j.core.layout.AbstractLayout<String>
org.apache.logging.log4j.core.layout.AbstractStringLayout
org.elasticsearch.common.logging.ESJsonLayout
All Implemented Interfaces:
org.apache.logging.log4j.core.impl.LocationAware, org.apache.logging.log4j.core.Layout<String>, org.apache.logging.log4j.core.layout.Encoder<org.apache.logging.log4j.core.LogEvent>, org.apache.logging.log4j.core.StringLayout

@Deprecated(since="v8") @Plugin(name="ESJsonLayout", category="Core", elementType="layout", printObject=true) public class ESJsonLayout extends org.apache.logging.log4j.core.layout.AbstractStringLayout
Deprecated.
ECSJsonlayout should be used as JSON logs layout
Formats log events as strings in a json format.

The class is wrapping the PatternLayout with a pattern to format into json. This gives more flexibility and control over how the log messages are formatted in JsonLayout There are fields which are always present in the log line:

  • type - the type of logs. These represent appenders and help docker distinguish log streams.
  • timestamp - ISO8601 with additional timezone ID
  • level - INFO, WARN etc
  • component - logger name, most of the times class name
  • cluster.name - taken from sys:es.logs.cluster_name system property because it is always set
  • node.name - taken from NodeNamePatternConverter, as it can be set in runtime as hostname when not set in elasticsearch.yml
  • node_and_cluster_id - in json as node.id and cluster.uuid - taken from NodeIdConverter and present once clusterStateUpdate is first received
  • message - a json escaped message. Multiline messages will be converted to single line with new line explicitly replaced to \n
  • exceptionAsJson - in json as a stacktrace field. Only present when throwable is passed as a parameter when using a logger. Taken from JsonThrowablePatternConverter

It is possible to add more field by using MapMessage.with(java.lang.String, boolean) method which allow adding key value pairs or override field with overrideFields appender.logger.layout.overrideFields=message. In the example above the pattern will be ... "message": %OverrideField{message} ... the message passed to a logger will be overridden with a value from %OverrideField{message} Once an appender is defined to be overriding a field, all the log events should contain this field.

The value taken from ESLogMessage has to be a simple escaped JSON value.

  • Nested Class Summary

    Nested Classes
    Modifier and Type
    Class
    Description
    static class 
    Deprecated.
     

    Nested classes/interfaces inherited from class org.apache.logging.log4j.core.layout.AbstractStringLayout

    org.apache.logging.log4j.core.layout.AbstractStringLayout.Serializer, org.apache.logging.log4j.core.layout.AbstractStringLayout.Serializer2
  • Field Summary

    Fields inherited from class org.apache.logging.log4j.core.layout.AbstractStringLayout

    DEFAULT_STRING_BUILDER_SIZE, MAX_STRING_BUILDER_SIZE

    Fields inherited from class org.apache.logging.log4j.core.layout.AbstractLayout

    configuration, eventCount, footer, header, LOGGER

    Fields inherited from interface org.apache.logging.log4j.core.Layout

    ELEMENT_TYPE
  • Constructor Summary

    Constructors
    Modifier
    Constructor
    Description
    protected
    ESJsonLayout(String typeName, Charset charset, String[] overrideFields)
    Deprecated.
     
  • Method Summary

    Modifier and Type
    Method
    Description
    createLayout(String type, Charset charset, String[] overrideFields)
    Deprecated.
     
    void
    encode(org.apache.logging.log4j.core.LogEvent event, org.apache.logging.log4j.core.layout.ByteBufferDestination destination)
    Deprecated.
     
    Deprecated.
     
    static <B extends ESJsonLayout.Builder<B>>
    B
    Deprecated.
     
    toSerializable(org.apache.logging.log4j.core.LogEvent event)
    Deprecated.
     
    Deprecated.
     

    Methods inherited from class org.apache.logging.log4j.core.layout.AbstractStringLayout

    getBytes, getCharset, getContentType, getFooter, getFooterSerializer, getHeader, getHeaderSerializer, getStringBuilder, getStringBuilderEncoder, requiresLocation, serializeToBytes, serializeToString, toByteArray, trimToMaxSize

    Methods inherited from class org.apache.logging.log4j.core.layout.AbstractLayout

    getConfiguration, markEvent

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
  • Constructor Details

    • ESJsonLayout

      protected ESJsonLayout(String typeName, Charset charset, String[] overrideFields)
      Deprecated.
  • Method Details

    • createLayout

      @PluginFactory public static ESJsonLayout createLayout(String type, Charset charset, String[] overrideFields)
      Deprecated.
    • newBuilder

      @PluginBuilderFactory public static <B extends ESJsonLayout.Builder<B>> B newBuilder()
      Deprecated.
    • toSerializable

      public String toSerializable(org.apache.logging.log4j.core.LogEvent event)
      Deprecated.
    • getContentFormat

      public Map<String,String> getContentFormat()
      Deprecated.
      Specified by:
      getContentFormat in interface org.apache.logging.log4j.core.Layout<String>
      Overrides:
      getContentFormat in class org.apache.logging.log4j.core.layout.AbstractLayout<String>
    • encode

      public void encode(org.apache.logging.log4j.core.LogEvent event, org.apache.logging.log4j.core.layout.ByteBufferDestination destination)
      Deprecated.
      Specified by:
      encode in interface org.apache.logging.log4j.core.layout.Encoder<org.apache.logging.log4j.core.LogEvent>
      Overrides:
      encode in class org.apache.logging.log4j.core.layout.AbstractLayout<String>
    • toString

      public String toString()
      Deprecated.
      Overrides:
      toString in class Object