Class GrowLogbackAppender
java.lang.Object
ch.qos.logback.core.spi.ContextAwareBase
ch.qos.logback.core.AppenderBase<ch.qos.logback.classic.spi.ILoggingEvent>
codes.grow.packages.betterstack.logging.GrowLogbackAppender
- All Implemented Interfaces:
ch.qos.logback.core.Appender<ch.qos.logback.classic.spi.ILoggingEvent>,ch.qos.logback.core.spi.ContextAware,ch.qos.logback.core.spi.FilterAttachable<ch.qos.logback.classic.spi.ILoggingEvent>,ch.qos.logback.core.spi.LifeCycle
public final class GrowLogbackAppender
extends ch.qos.logback.core.AppenderBase<ch.qos.logback.classic.spi.ILoggingEvent>
Logback appender that forwards events to a
LogClient (Logback is an optional,
provided dependency).
LoggerContext ctx = (LoggerContext) LoggerFactory.getILoggerFactory();
GrowLogbackAppender.install(ctx, logClient);
When configured in logback.xml, call setLogClient(codes.grow.packages.betterstack.logging.LogClient) on the appender (found with
ctx.getLogger("ROOT").getAppender(name)) before it starts, or use install(ch.qos.logback.classic.LoggerContext, codes.grow.packages.betterstack.logging.LogClient). MDC
entries and SLF4J key-value pairs become attributes, together with logger.name,
thread.name and the exception.* attributes.
-
Field Summary
Fields inherited from class ch.qos.logback.core.AppenderBase
name, startedFields inherited from class ch.qos.logback.core.spi.ContextAwareBase
context -
Constructor Summary
ConstructorsConstructorDescriptionCreates an appender without a client (set it withsetLogClient(codes.grow.packages.betterstack.logging.LogClient)).GrowLogbackAppender(LogClient client) Creates an appender forclient. -
Method Summary
Modifier and TypeMethodDescriptionprotected voidappend(ch.qos.logback.classic.spi.ILoggingEvent event) Returns the destination.static GrowLogbackAppenderCreates, starts and attaches an appender named"GROW"to the root logger.voidsetLogClient(LogClient client) Sets the destination.static SeverityseverityOf(ch.qos.logback.classic.Level level) Maps a Logback level to a severity.voidstart()Methods inherited from class ch.qos.logback.core.AppenderBase
addFilter, clearAllFilters, doAppend, getCopyOfAttachedFiltersList, getFilterChainDecision, getName, isStarted, setName, stop, toStringMethods inherited from class ch.qos.logback.core.spi.ContextAwareBase
addError, addError, addInfo, addInfo, addStatus, addWarn, addWarn, getContext, getDeclaredOrigin, getStatusManager, setContextMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface ch.qos.logback.core.spi.ContextAware
addError, addError, addInfo, addInfo, addStatus, addWarn, addWarn, getContext, setContext
-
Constructor Details
-
GrowLogbackAppender
public GrowLogbackAppender()Creates an appender without a client (set it withsetLogClient(codes.grow.packages.betterstack.logging.LogClient)). -
GrowLogbackAppender
Creates an appender forclient.- Parameters:
client- destination
-
-
Method Details
-
install
public static GrowLogbackAppender install(ch.qos.logback.classic.LoggerContext context, LogClient client) Creates, starts and attaches an appender named"GROW"to the root logger.- Parameters:
context- logback contextclient- destination- Returns:
- the started appender
-
setLogClient
Sets the destination.- Parameters:
client- destination
-
getLogClient
Returns the destination.- Returns:
- client or
null
-
severityOf
Maps a Logback level to a severity.- Parameters:
level- level- Returns:
- severity
-
start
public void start()- Specified by:
startin interfacech.qos.logback.core.spi.LifeCycle- Overrides:
startin classch.qos.logback.core.AppenderBase<ch.qos.logback.classic.spi.ILoggingEvent>
-
append
protected void append(ch.qos.logback.classic.spi.ILoggingEvent event) - Specified by:
appendin classch.qos.logback.core.AppenderBase<ch.qos.logback.classic.spi.ILoggingEvent>
-