Package com.logfire.logback
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>
-
Nested Class Summary
Nested Classes -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected Stringprotected Vector<ch.qos.logback.classic.spi.ILoggingEvent> protected intprotected intprotected intprotected com.fasterxml.jackson.databind.ObjectMapperprotected booleanprotected ch.qos.logback.classic.encoder.PatternLayoutEncoderprotected Stringprotected AtomicBooleanprotected org.slf4j.Loggerprotected intprotected intprotected booleanprotected intprotected intprotected intprotected intprotected ScheduledExecutorServiceprotected ScheduledFuture<?> protected Stringprotected ThreadFactoryprotected Stringprotected booleanFields inherited from class ch.qos.logback.core.UnsynchronizedAppenderBase
name, startedFields inherited from class ch.qos.logback.core.spi.ContextAwareBase
context -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected voidappend(ch.qos.logback.classic.spi.ILoggingEvent event) protected StringbatchToJson(int flushedSize) buildPostData(ch.qos.logback.classic.spi.ILoggingEvent event) protected LogfireResponsecallHttpURLConnection(int flushedSize) protected voidflush()protected booleanflushLogs(int flushedSize) protected StringgenerateLogMessage(ch.qos.logback.classic.spi.ILoggingEvent event) generateLogMeta(ch.qos.logback.classic.spi.ILoggingEvent event) generateLogRuntime(ch.qos.logback.classic.spi.ILoggingEvent event) generateLogThrowable(ch.qos.logback.classic.spi.IThrowableProxy throwable) intGet the batch size for the number of messages to be sent via the APIprotected HttpURLConnectionprotected ObjectgetMetaValue(String type, String value) booleanvoidsetAppName(String appName) Sets the application name for Logfire indexation.voidsetBatchInterval(int batchInterval) Sets the maximum wait time for a batch to be sent via the API, in milliseconds.voidsetBatchSize(int batchSize) Sets the batch size for the number of messages to be sent via the APIvoidsetConnectTimeout(int connectTimeout) Sets the connection timeout of the underlying HTTP client, in milliseconds.voidsetEncoder(ch.qos.logback.classic.encoder.PatternLayoutEncoder encoder) voidsetIngestKey(String ingestKey) Deprecated! Kept for backward compatibility.voidsetIngestUrl(String ingestUrl) Sets the Logfire ingest API url.voidsetMaxQueueSize(int maxQueueSize) Sets the maximum number of messages in the queue.voidsetMaxRetries(int maxRetries) Sets the maximum number of retries for sending logs to Logfire.voidsetMdcFields(String mdcFields) Sets the MDC fields that will be sent as metadata, separated by a comma.voidsetMdcTypes(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.voidsetObjectMapperModule(String className) Registers a dynamically loaded Module object to ObjectMapper used for serialization of logged data.voidsetReadTimeout(int readTimeout) Sets the read timeout of the underlying HTTP client, in milliseconds.voidsetRetrySleepMilliseconds(int retrySleepMilliseconds) Sets the number of milliseconds to sleep before retrying to send logs to Logfire.voidsetSourceToken(String sourceToken) Sets your Logfire source token.voidsetUserAgent(String userAgent) protected voidstartThread(String threadName, Runnable runnable) voidstop()Methods inherited from class ch.qos.logback.core.UnsynchronizedAppenderBase
addFilter, clearAllFilters, doAppend, getCopyOfAttachedFiltersList, getFilterChainDecision, getName, isStarted, setName, start, 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
-
Field Details
-
appName
-
ingestUrl
-
sourceToken
-
userAgent
-
mdcFields
-
mdcTypes
-
maxQueueSize
-
batchSize
-
batchInterval
-
connectTimeout
-
readTimeout
-
maxRetries
-
retrySleepMilliseconds
-
encoder
-
batch
-
isFlushing
-
mustReflush
-
warnAboutMaxQueueSize
-
scheduledExecutorService
-
scheduledFuture
-
dataMapper
-
logger
-
retrySize
-
retries
-
disabled
-
threadFactory
-
-
Constructor Details
-
LogfireAppender
public LogfireAppender()
-
-
Method Details
-
append
- Specified by:
appendin classch.qos.logback.core.UnsynchronizedAppenderBase<ch.qos.logback.classic.spi.ILoggingEvent>
-
startThread
-
flush
-
flushLogs
-
callHttpURLConnection
- Throws:
IOException
-
getHttpURLConnection
- Throws:
IOException
-
batchToJson
protected String batchToJson(int flushedSize) throws com.fasterxml.jackson.core.JsonProcessingException - Throws:
com.fasterxml.jackson.core.JsonProcessingException
-
buildPostData
-
generateLogMessage
-
generateLogMeta
-
generateLogRuntime
-
generateLogThrowable
protected Map<String,Object> generateLogThrowable(ch.qos.logback.classic.spi.IThrowableProxy throwable) -
getMetaValue
-
setAppName
Sets the application name for Logfire indexation.- Parameters:
appName- application name
-
setIngestUrl
Sets the Logfire ingest API url.- Parameters:
ingestUrl- Logfire ingest url
-
setSourceToken
Sets your Logfire source token.- Parameters:
sourceToken- your Logfire source token
-
setIngestKey
Deprecated! Kept for backward compatibility. Sets your Logfire source token if unset.- Parameters:
ingestKey- your Logfire source token
-
setUserAgent
-
setMdcFields
Sets the MDC fields that will be sent as metadata, separated by a comma.- Parameters:
mdcFields- MDC fields to include in structured logs
-
setMdcTypes
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
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
Sets the batch size for the number of messages to be sent via the API- Parameters:
batchSize- size of the message batch
-
getBatchSize
Get the batch size for the number of messages to be sent via the API -
setBatchInterval
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
Sets the connection timeout of the underlying HTTP client, in milliseconds.- Parameters:
connectTimeout- client connection timeout [ms]
-
setReadTimeout
Sets the read timeout of the underlying HTTP client, in milliseconds.- Parameters:
readTimeout- client read timeout
-
setMaxRetries
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
Sets the number of milliseconds to sleep before retrying to send logs to Logfire.- Parameters:
retrySleepMilliseconds- number of milliseconds to sleep before retry
-
setObjectMapperModule
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
-
isDisabled
-
stop
- Specified by:
stopin interfacech.qos.logback.core.spi.LifeCycle- Overrides:
stopin classch.qos.logback.core.UnsynchronizedAppenderBase<ch.qos.logback.classic.spi.ILoggingEvent>
-