Class CachingSLF4JAppender

  • 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 class CachingSLF4JAppender
    extends ch.qos.logback.core.AppenderBase<ch.qos.logback.classic.spi.ILoggingEvent>
    SLF4J appender that caches a certain number of log entries in a cyclic manor. "DEBUG and TRACE entries are excluded".
    • Field Summary

      Fields 
      Modifier and Type Field Description
      protected int currentIndex
      The place in the loggingHistory for the next LogRecord.
      protected ch.qos.logback.classic.PatternLayout layout
      Pattern layouter used to format log string.
      protected List<String> loggingHistory
      The logging cache itself, caching the last "loggingHistorySize" log entries.
      protected int loggingHistorySize
      The size of the logging cache.
      protected List<CachingSLF4JLogRecord> loggingMBeans
      The log entries exposed as MBeans.
      protected String pattern
      Log format string pattern.
      • 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
      CachingSLF4JAppender()
      Initialize an instance of this class.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      protected void append​(ch.qos.logback.classic.spi.ILoggingEvent event)  
      void close()
      Close the appender and release associated resources.
      String getNthLogRecord​(int n)
      Returns the nth logrecord from the top.
      String getPattern()
      Returns the pattern used to format the log string.
      void setContext​(ch.qos.logback.core.Context context)  
      void setPattern​(String pattern)
      Set the pattern used to format the log string.
      void start()  
      void stop()  
      • Methods inherited from class ch.qos.logback.core.AppenderBase

        addFilter, clearAllFilters, doAppend, getCopyOfAttachedFiltersList, getFilterChainDecision, getName, isStarted, setName, toString
      • Methods inherited from class ch.qos.logback.core.spi.ContextAwareBase

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

        addError, addError, addInfo, addInfo, addStatus, addWarn, addWarn, getContext
    • Field Detail

      • pattern

        protected String pattern
        Log format string pattern.
      • layout

        protected ch.qos.logback.classic.PatternLayout layout
        Pattern layouter used to format log string.
      • loggingHistorySize

        protected final int loggingHistorySize
        The size of the logging cache.
      • loggingHistory

        protected final List<String> loggingHistory
        The logging cache itself, caching the last "loggingHistorySize" log entries.
      • currentIndex

        protected int currentIndex
        The place in the loggingHistory for the next LogRecord.
    • Constructor Detail

      • CachingSLF4JAppender

        public CachingSLF4JAppender()
        Initialize an instance of this class.
    • Method Detail

      • getPattern

        public String getPattern()
        Returns the pattern used to format the log string.
        Returns:
        the pattern used to format the log string
      • setPattern

        public void setPattern​(String pattern)
        Set the pattern used to format the log string. The method should be called before the setContext() or start() methods, most notably if used programmatically..
        Parameters:
        pattern - log pattern
      • setContext

        public void setContext​(ch.qos.logback.core.Context context)
        Specified by:
        setContext in interface ch.qos.logback.core.spi.ContextAware
        Overrides:
        setContext in class ch.qos.logback.core.spi.ContextAwareBase
      • 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>
      • stop

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

        public void close()
        Close the appender and release associated resources.
      • 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>
      • getNthLogRecord

        public String getNthLogRecord​(int n)
        Returns the nth logrecord from the top.
        Parameters:
        n - The number of the log record to get
        Returns:
        The LogRecord which is number n from the top, or null for none.