Package com.github.loki4j.logback.json
Class AbstractFieldJsonProvider
- java.lang.Object
-
- ch.qos.logback.core.spi.ContextAwareBase
-
- com.github.loki4j.logback.json.AbstractFieldJsonProvider
-
- All Implemented Interfaces:
ch.qos.logback.core.spi.ContextAware,ch.qos.logback.core.spi.LifeCycle,JsonProvider<ch.qos.logback.classic.spi.ILoggingEvent>
- Direct Known Subclasses:
LoggerNameJsonProvider,LogLevelJsonProvider,MdcJsonProvider,MessageJsonProvider,StackTraceJsonProvider,ThreadNameJsonProvider,TimestampJsonProvider
public abstract class AbstractFieldJsonProvider extends ch.qos.logback.core.spi.ContextAwareBase implements JsonProvider<ch.qos.logback.classic.spi.ILoggingEvent>
An abstract provider that writes a certain aspect of a logging event as a JSON field
-
-
Constructor Summary
Constructors Constructor Description AbstractFieldJsonProvider()
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description booleancanWrite(ch.qos.logback.classic.spi.ILoggingEvent event)Indicates if this provider can write anything for a particular event.java.lang.StringgetFieldName()booleanisEnabled()Indicates if this provider is enabled.booleanisStarted()voidsetEnabled(boolean enabled)Allows to configure if the provider is enabled.voidsetFieldName(java.lang.String fieldName)voidstart()voidstop()protected abstract voidwriteExactlyOneField(JsonEventWriter writer, ch.qos.logback.classic.spi.ILoggingEvent event)Write exactly one field into JSON event layout.booleanwriteTo(JsonEventWriter writer, ch.qos.logback.classic.spi.ILoggingEvent event, boolean startWithSeparator)Writes a certain aspect of event into a writer.-
Methods inherited from class ch.qos.logback.core.spi.ContextAwareBase
addError, addError, addInfo, addInfo, addStatus, addWarn, addWarn, getContext, getDeclaredOrigin, getStatusManager, setContext
-
-
-
-
Method Detail
-
canWrite
public boolean canWrite(ch.qos.logback.classic.spi.ILoggingEvent event)
Description copied from interface:JsonProviderIndicates if this provider can write anything for a particular event. If this method returnsfalse,writeTo()should not be called for a particular event. You can put all your preliminary checks here, no need to duplicated them inwriteTo().- Specified by:
canWritein interfaceJsonProvider<ch.qos.logback.classic.spi.ILoggingEvent>
-
writeTo
public boolean writeTo(JsonEventWriter writer, ch.qos.logback.classic.spi.ILoggingEvent event, boolean startWithSeparator)
Description copied from interface:JsonProviderWrites a certain aspect of event into a writer.- Specified by:
writeToin interfaceJsonProvider<ch.qos.logback.classic.spi.ILoggingEvent>- Parameters:
writer- JSON writer to use.event- Current logback event.startWithSeparator- Iftrue, a separator should be written before writing anything else.- Returns:
- If anything was effectively written during this call.
-
writeExactlyOneField
protected abstract void writeExactlyOneField(JsonEventWriter writer, ch.qos.logback.classic.spi.ILoggingEvent event)
Write exactly one field into JSON event layout.- Parameters:
writer- JSON writer to use.event- Current logback event.
-
start
public void start()
- Specified by:
startin interfacech.qos.logback.core.spi.LifeCycle
-
stop
public void stop()
- Specified by:
stopin interfacech.qos.logback.core.spi.LifeCycle
-
isStarted
public boolean isStarted()
- Specified by:
isStartedin interfacech.qos.logback.core.spi.LifeCycle
-
isEnabled
public boolean isEnabled()
Description copied from interface:JsonProviderIndicates if this provider is enabled. For a disabled provider no other its methods should be called.- Specified by:
isEnabledin interfaceJsonProvider<ch.qos.logback.classic.spi.ILoggingEvent>
-
setEnabled
public void setEnabled(boolean enabled)
Description copied from interface:JsonProviderAllows to configure if the provider is enabled.- Specified by:
setEnabledin interfaceJsonProvider<ch.qos.logback.classic.spi.ILoggingEvent>
-
getFieldName
public java.lang.String getFieldName()
-
setFieldName
public void setFieldName(java.lang.String fieldName)
-
-