Package net.zileo.logback.logdna
Class LogDnaAppender
java.lang.Object
ch.qos.logback.core.spi.ContextAwareBase
ch.qos.logback.core.UnsynchronizedAppenderBase<ch.qos.logback.classic.spi.ILoggingEvent>
net.zileo.logback.logdna.LogDnaAppender
- 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 LogDnaAppender extends ch.qos.logback.core.UnsynchronizedAppenderBase<ch.qos.logback.classic.spi.ILoggingEvent>
Logback appender for sending logs to LogDNA.com.
- Author:
- jlannoy
-
Field Summary
Fields Modifier and Type Field Description protected StringappNameprotected longconnectTimeoutprotected ch.qos.logback.classic.encoder.PatternLayoutEncoderencoderprotected javax.ws.rs.core.MultivaluedMap<String,Object>headersprotected Stringhostnameprotected StringingestUrlprotected List<String>mdcFieldsprotected List<String>mdcTypesprotected longreadTimeoutprotected Stringtagsprotected booleanuseTimeDrift -
Constructor Summary
Constructors Constructor Description LogDnaAppender()Appender initialization. -
Method Summary
Modifier and Type Method Description protected voidappend(ch.qos.logback.classic.spi.ILoggingEvent event)protected Map<String,Object>buildPostData(ch.qos.logback.classic.spi.ILoggingEvent event)Converts a logback logging event to a JSON oriented map.protected javax.ws.rs.core.ResponsecallIngestApi(String jsonData)Call LogDna API posting given JSON formated string.protected javax.ws.rs.client.Clientclient()protected StringconvertLogEventToJson(ch.qos.logback.classic.spi.ILoggingEvent event)protected LogDnaResponseconvertResponseToObject(javax.ws.rs.core.Response response)booleanisDisabled()voidsetAppName(String appName)Sets the application name for LogDNA indexation.voidsetConnectTimeout(Long connectTimeout)Sets the connection timeout of the underlying HTTP client, in milliseconds.voidsetEncoder(ch.qos.logback.classic.encoder.PatternLayoutEncoder encoder)voidsetHostname(String hostname)Force a given value for the hostname LogDNA parameter.voidsetIngestKey(String ingestKey)Sets your LogDNA ingest API key.voidsetIngestUrl(String ingestUrl)Sets the LogDNA ingest API url.voidsetMdcFields(String mdcFields)Sets the MDC fields that needs to be sent inside LogDNA metadata, separated by a comma.voidsetMdcTypes(String mdcTypes)Sets the MDC fields types that will be sent inside LogDNA metadata, in the same order as mdcFields are set up, separated by a comma.voidsetReadTimeout(Long readTimeout)Sets the read timeout of the underlying HTTP client, in milliseconds.voidsetTags(String tags)Sets the tags that needs to be sent to LogDNA, for grouping hosts for example.voidsetUseTimeDrift(String useTimeDrift)Set whether using time drift.Methods inherited from class ch.qos.logback.core.UnsynchronizedAppenderBase
addFilter, clearAllFilters, doAppend, getCopyOfAttachedFiltersList, getFilterChainDecision, getName, isStarted, setName, start, stop, toStringMethods inherited from class ch.qos.logback.core.spi.ContextAwareBase
addError, addError, addInfo, addInfo, addStatus, addWarn, addWarn, getContext, getDeclaredOrigin, getStatusManager, setContext
-
Field Details
-
Constructor Details
-
LogDnaAppender
public LogDnaAppender()Appender initialization.
-
-
Method Details
-
client
-
append
- Specified by:
appendin classch.qos.logback.core.UnsynchronizedAppenderBase<ch.qos.logback.classic.spi.ILoggingEvent>- See Also:
UnsynchronizedAppenderBase.append(java.lang.Object)
-
convertLogEventToJson
protected String convertLogEventToJson(ch.qos.logback.classic.spi.ILoggingEvent event) throws com.fasterxml.jackson.core.JsonProcessingException- Throws:
com.fasterxml.jackson.core.JsonProcessingException
-
convertResponseToObject
protected LogDnaResponse convertResponseToObject(javax.ws.rs.core.Response response) throws com.fasterxml.jackson.core.JsonProcessingException- Throws:
com.fasterxml.jackson.core.JsonProcessingException
-
callIngestApi
Call LogDna API posting given JSON formated string.- Parameters:
jsonData- a json oriented map- Returns:
- the http response
-
buildPostData
Converts a logback logging event to a JSON oriented map.- Parameters:
event- the logging event- Returns:
- a json oriented map
-
setEncoder
-
setAppName
Sets the application name for LogDNA indexation.- Parameters:
appName- application name
-
setIngestUrl
Sets the LogDNA ingest API url.- Parameters:
ingestUrl- logdna url
-
setIngestKey
Sets your LogDNA ingest API key.- Parameters:
ingestKey- your ingest key
-
setMdcFields
Sets the MDC fields that needs to be sent inside LogDNA metadata, separated by a comma.- Parameters:
mdcFields- MDC fields to use
-
setMdcTypes
Sets the MDC fields types that will be sent inside LogDNA metadata, in the same order as mdcFields are set up, separated by a comma. Possible values are string, boolean, int and long. The last two will result as an indexed number in LogDNA's console.- Parameters:
mdcTypes- MDC fields types
-
setTags
Sets the tags that needs to be sent to LogDNA, for grouping hosts for example.- Parameters:
tags- fixed tags
-
setUseTimeDrift
Set whether using time drift. If set true, now parameter is supplied (https://docs.logdna.com/reference).- Parameters:
useTimeDrift- true: Use time drift. false: Do not use time drift.
-
setHostname
Force a given value for the hostname LogDNA parameter.- Parameters:
hostname- local hostname value
-
setConnectTimeout
Sets the connection timeout of the underlying HTTP client, in milliseconds.- Parameters:
connectTimeout- client connection timeout
-
setReadTimeout
Sets the read timeout of the underlying HTTP client, in milliseconds.- Parameters:
readTimeout- client read timeout
-
isDisabled
-