Class JsonLog4j2Layout

  • 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

    @Plugin(name="JsonLog4j2Layout",
            category="Core",
            elementType="layout",
            printObject=true)
    public class JsonLog4j2Layout
    extends org.apache.logging.log4j.core.layout.AbstractStringLayout
    Layout for log4j to emit JSON format, including exceptions. In addition, it will also append all values added to the current thread with Context class.
    Author:
    igor on 1/12/17.
    • Nested Class Summary

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

        org.apache.logging.log4j.core.layout.AbstractStringLayout.Builder<B extends org.apache.logging.log4j.core.layout.AbstractStringLayout.Builder<B>>, 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
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      static JsonLog4j2Layout createLayout​(Charset charset, String dateFormat)  
      String toSerializable​(org.apache.logging.log4j.core.LogEvent event)
      Formats a LogEvent.
      • 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

        encode, getConfiguration, getContentFormat, markEvent
      • Methods inherited from interface org.apache.logging.log4j.core.layout.Encoder

        encode
      • Methods inherited from interface org.apache.logging.log4j.core.Layout

        getContentFormat
    • Constructor Detail

      • JsonLog4j2Layout

        protected JsonLog4j2Layout()
      • JsonLog4j2Layout

        protected JsonLog4j2Layout​(Charset charset,
                                   String dateFormat)
    • Method Detail

      • toSerializable

        public String toSerializable​(org.apache.logging.log4j.core.LogEvent event)
        Formats a LogEvent.
        Parameters:
        event - The LogEvent.
        Returns:
        The XML representation of the LogEvent.
      • createLayout

        @PluginFactory
        public static JsonLog4j2Layout createLayout​(@PluginAttribute(value="charset",defaultString="UTF-8")
                                                    Charset charset,
                                                    @PluginAttribute(value="dateFormat",defaultString="yyyy-MM-dd HH:mm:ss.SSS")
                                                    String dateFormat)