Class LogbackToMetricsAppender

java.lang.Object
ch.qos.logback.core.spi.ContextAwareBase
ch.qos.logback.core.UnsynchronizedAppenderBase<E>
ch.qos.logback.core.OutputStreamAppender<ch.qos.logback.classic.spi.ILoggingEvent>
io.github.dordor12.LogbackToMetricsAppender
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 LogbackToMetricsAppender extends ch.qos.logback.core.OutputStreamAppender<ch.qos.logback.classic.spi.ILoggingEvent>
A Logback appender that converts log events into Micrometer metrics. This appender extracts key-value pairs from log events and creates counters based on configurable whitelist and blacklist filters.
  • Field Summary

    Fields inherited from class ch.qos.logback.core.OutputStreamAppender

    encoder, lock

    Fields inherited from class ch.qos.logback.core.UnsynchronizedAppenderBase

    name, started

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

    context
  • Constructor Summary

    Constructors
    Constructor
    Description
    Default constructor that initializes the appender with an empty output stream.
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    Adds a key to the blacklist for metric tag extraction.
    void
    Adds a key to the whitelist for metric tag extraction.
    void
    append(ch.qos.logback.classic.spi.ILoggingEvent eventObject)
     

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

    closeOutputStream, getEncoder, getOutputStream, isImmediateFlush, setEncoder, setImmediateFlush, setLayout, setOutputStream, start, stop, subAppend, writeOut

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

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

    • LogbackToMetricsAppender

      public LogbackToMetricsAppender()
      Default constructor that initializes the appender with an empty output stream. The actual output is handled by creating metrics instead of writing to a stream.
  • Method Details

    • addKvWhitelist

      public void addKvWhitelist(String whiteList)
      Adds a key to the whitelist for metric tag extraction. Only keys in the whitelist will be included as metric tags. This method is called by Logback when parsing XML configuration.
      Parameters:
      whiteList - the key to add to the whitelist
    • addKvBlacklist

      public void addKvBlacklist(String blackList)
      Adds a key to the blacklist for metric tag extraction. Keys in the blacklist will be excluded from metric tags. This method is called by Logback when parsing XML configuration.
      Parameters:
      blackList - the key to add to the blacklist
    • append

      public void append(ch.qos.logback.classic.spi.ILoggingEvent eventObject)
      Overrides:
      append in class ch.qos.logback.core.OutputStreamAppender<ch.qos.logback.classic.spi.ILoggingEvent>