Class LogfireAppender

java.lang.Object
ch.qos.logback.core.spi.ContextAwareBase
ch.qos.logback.core.UnsynchronizedAppenderBase<ch.qos.logback.classic.spi.ILoggingEvent>
com.logfire.logback.LogfireAppender
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 LogfireAppender extends ch.qos.logback.core.UnsynchronizedAppenderBase<ch.qos.logback.classic.spi.ILoggingEvent>
  • Field Details

  • Constructor Details

  • Method Details

    • append

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

      protected void startThread(String threadName, Runnable runnable)
    • flush

      protected void flush()
    • flushLogs

      protected boolean flushLogs(int flushedSize)
    • callHttpURLConnection

      protected LogfireResponse callHttpURLConnection(int flushedSize) throws IOException
      Throws:
      IOException
    • getHttpURLConnection

      Throws:
      IOException
    • batchToJson

      protected String batchToJson(int flushedSize) throws com.fasterxml.jackson.core.JsonProcessingException
      Throws:
      com.fasterxml.jackson.core.JsonProcessingException
    • buildPostData

      protected Map<String,Object> buildPostData(ch.qos.logback.classic.spi.ILoggingEvent event)
    • generateLogMessage

      protected String generateLogMessage(ch.qos.logback.classic.spi.ILoggingEvent event)
    • generateLogMeta

      protected Map<String,Object> generateLogMeta(ch.qos.logback.classic.spi.ILoggingEvent event)
    • generateLogRuntime

      protected Map<String,Object> generateLogRuntime(ch.qos.logback.classic.spi.ILoggingEvent event)
    • generateLogThrowable

      protected Map<String,Object> generateLogThrowable(ch.qos.logback.classic.spi.IThrowableProxy throwable)
    • getMetaValue

      protected Object getMetaValue(String type, String value)
    • setAppName

      public void setAppName(String appName)
      Sets the application name for Logfire indexation.
      Parameters:
      appName - application name
    • setIngestUrl

      public void setIngestUrl(String ingestUrl)
      Sets the Logfire ingest API url.
      Parameters:
      ingestUrl - Logfire ingest url
    • setSourceToken

      public void setSourceToken(String sourceToken)
      Sets your Logfire source token.
      Parameters:
      sourceToken - your Logfire source token
    • setIngestKey

      public void setIngestKey(String ingestKey)
      Deprecated! Kept for backward compatibility. Sets your Logfire source token if unset.
      Parameters:
      ingestKey - your Logfire source token
    • setUserAgent

      public void setUserAgent(String userAgent)
    • setMdcFields

      public void setMdcFields(String mdcFields)
      Sets the MDC fields that will be sent as metadata, separated by a comma.
      Parameters:
      mdcFields - MDC fields to include in structured logs
    • setMdcTypes

      public void setMdcTypes(String mdcTypes)
      Sets the MDC fields types that will be sent as metadata, in the same order as mdcFields are set up, separated by a comma. Possible values are string, boolean, int and long.
      Parameters:
      mdcTypes - MDC fields types
    • setMaxQueueSize

      public void setMaxQueueSize(int maxQueueSize)
      Sets the maximum number of messages in the queue. Messages over the limit will be dropped.
      Parameters:
      maxQueueSize - max size of the message queue
    • setBatchSize

      public void setBatchSize(int batchSize)
      Sets the batch size for the number of messages to be sent via the API
      Parameters:
      batchSize - size of the message batch
    • getBatchSize

      public int getBatchSize()
      Get the batch size for the number of messages to be sent via the API
    • setBatchInterval

      public void setBatchInterval(int batchInterval)
      Sets the maximum wait time for a batch to be sent via the API, in milliseconds.
      Parameters:
      batchInterval - maximum wait time for message batch [ms]
    • setConnectTimeout

      public void setConnectTimeout(int connectTimeout)
      Sets the connection timeout of the underlying HTTP client, in milliseconds.
      Parameters:
      connectTimeout - client connection timeout [ms]
    • setReadTimeout

      public void setReadTimeout(int readTimeout)
      Sets the read timeout of the underlying HTTP client, in milliseconds.
      Parameters:
      readTimeout - client read timeout
    • setMaxRetries

      public void setMaxRetries(int maxRetries)
      Sets the maximum number of retries for sending logs to Logfire. After that, current batch of logs will be dropped.
      Parameters:
      maxRetries - max number of retries for sending logs
    • setRetrySleepMilliseconds

      public void setRetrySleepMilliseconds(int retrySleepMilliseconds)
      Sets the number of milliseconds to sleep before retrying to send logs to Logfire.
      Parameters:
      retrySleepMilliseconds - number of milliseconds to sleep before retry
    • setObjectMapperModule

      public void setObjectMapperModule(String className)
      Registers a dynamically loaded Module object to ObjectMapper used for serialization of logged data.
      Parameters:
      className - fully qualified class name of the module, eg. "com.fasterxml.jackson.datatype.jsr310.JavaTimeModule"
    • setEncoder

      public void setEncoder(ch.qos.logback.classic.encoder.PatternLayoutEncoder encoder)
    • isDisabled

      public boolean isDisabled()
    • stop

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