Class JsonEncoder

  • All Implemented Interfaces:
    ch.qos.logback.core.encoder.Encoder<ch.qos.logback.classic.spi.ILoggingEvent>, ch.qos.logback.core.spi.ContextAware, ch.qos.logback.core.spi.LifeCycle

    public class JsonEncoder
    extends ch.qos.logback.core.encoder.LayoutWrappingEncoder<ch.qos.logback.classic.spi.ILoggingEvent>
    A LayoutWrappingEncoder implementation that encodes an ILoggingEvent as a JSON object.

    Under the hood, it's using a couple of PatternLayout instances to support different logging contexts. These patterns are specified in LayoutPatterns, so there's no need/way to do that in the logback configuration file. There, you should only specify that you use this encoder with an appender, for example like this:

     <appender name="STDOUT-JSON" class="ch.qos.logback.core.ConsoleAppender">
        <encoder class="com.sap.hcp.cf.logback.encoder.JsonEncoder"/>
     </appender>
     
    • Nested Class Summary

      Nested Classes 
      Modifier and Type Class Description
      static class  JsonEncoder.JsonLayout  
    • Field Summary

      • Fields inherited from class ch.qos.logback.core.encoder.LayoutWrappingEncoder

        layout
      • Fields inherited from class ch.qos.logback.core.encoder.EncoderBase

        started
      • Fields inherited from class ch.qos.logback.core.spi.ContextAwareBase

        context
    • Constructor Summary

      Constructors 
      Constructor Description
      JsonEncoder()  
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void addCustomFieldMdcKeyName​(String name)  
      void addRetainFieldMdcKeyName​(String name)  
      void start()  
      • Methods inherited from class ch.qos.logback.core.encoder.LayoutWrappingEncoder

        encode, footerBytes, getCharset, getLayout, headerBytes, isStarted, setCharset, setImmediateFlush, setLayout, setParent, stop
      • Methods inherited from class ch.qos.logback.core.spi.ContextAwareBase

        addError, addError, addInfo, addInfo, addStatus, addWarn, addWarn, getContext, getDeclaredOrigin, getStatusManager, setContext
      • Methods inherited from interface ch.qos.logback.core.spi.ContextAware

        addError, addError, addInfo, addInfo, addStatus, addWarn, addWarn, getContext, setContext
    • Constructor Detail

      • JsonEncoder

        public JsonEncoder()
    • Method Detail

      • addCustomFieldMdcKeyName

        public void addCustomFieldMdcKeyName​(String name)
      • addRetainFieldMdcKeyName

        public void addRetainFieldMdcKeyName​(String name)
      • start

        public void start()
        Specified by:
        start in interface ch.qos.logback.core.spi.LifeCycle
        Overrides:
        start in class ch.qos.logback.core.encoder.LayoutWrappingEncoder<ch.qos.logback.classic.spi.ILoggingEvent>