Package com.sap.hcp.cf.logback.encoder
Class JsonEncoder
- java.lang.Object
-
- ch.qos.logback.core.spi.ContextAwareBase
-
- ch.qos.logback.core.encoder.EncoderBase<E>
-
- ch.qos.logback.core.encoder.LayoutWrappingEncoder<ch.qos.logback.classic.spi.ILoggingEvent>
-
- com.sap.hcp.cf.logback.encoder.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>
ALayoutWrappingEncoder
implementation that encodes anILoggingEvent
as a JSON object.Under the hood, it's using a couple of
PatternLayout
instances to support different logging contexts. These patterns are specified inLayoutPatterns
, 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
-
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
-
-
-
-
Method Detail
-
addCustomFieldMdcKeyName
public void addCustomFieldMdcKeyName(String name)
-
addRetainFieldMdcKeyName
public void addRetainFieldMdcKeyName(String name)
-
start
public void start()
- Specified by:
start
in interfacech.qos.logback.core.spi.LifeCycle
- Overrides:
start
in classch.qos.logback.core.encoder.LayoutWrappingEncoder<ch.qos.logback.classic.spi.ILoggingEvent>
-
-