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, started

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

    context
  • Constructor Summary

    Constructors
    Constructor
    Description
    Creates an appender without a client (set it with setLogClient(codes.grow.packages.betterstack.logging.LogClient)).
    Creates an appender for client.
  • Method Summary

    Modifier and Type
    Method
    Description
    protected void
    append(ch.qos.logback.classic.spi.ILoggingEvent event)
     
    Returns the destination.
    install(ch.qos.logback.classic.LoggerContext context, LogClient client)
    Creates, starts and attaches an appender named "GROW" to the root logger.
    void
    Sets the destination.
    static Severity
    severityOf(ch.qos.logback.classic.Level level)
    Maps a Logback level to a severity.
    void
     

    Methods inherited from class ch.qos.logback.core.AppenderBase

    addFilter, clearAllFilters, doAppend, getCopyOfAttachedFiltersList, getFilterChainDecision, getName, isStarted, setName, stop, toString

    Methods inherited from class ch.qos.logback.core.spi.ContextAwareBase

    addError, addError, addInfo, addInfo, addStatus, addWarn, addWarn, getContext, getDeclaredOrigin, getStatusManager, setContext

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait

    Methods inherited from interface ch.qos.logback.core.spi.ContextAware

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

  • 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 context
      client - destination
      Returns:
      the started appender
    • setLogClient

      public void setLogClient(LogClient client)
      Sets the destination.
      Parameters:
      client - destination
    • getLogClient

      public LogClient getLogClient()
      Returns the destination.
      Returns:
      client or null
    • severityOf

      public static Severity severityOf(ch.qos.logback.classic.Level level)
      Maps a Logback level to a severity.
      Parameters:
      level - level
      Returns:
      severity
    • start

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

      protected void append(ch.qos.logback.classic.spi.ILoggingEvent event)
      Specified by:
      append in class ch.qos.logback.core.AppenderBase<ch.qos.logback.classic.spi.ILoggingEvent>