public class LogglyBatchAppender<E> extends AbstractLogglyAppender<E> implements LogglyBatchAppenderMBean
Logback batch appender for Loggly HTTP API.
Note:Loggly's Syslog API is much more scalable than the HTTP API which should mostly be used in low-volume or non-production systems. The HTTP API can be very convenient to workaround firewalls.
If the LogglyBatchAppender saturates and discards log messages, the following warning message is
appended to both Loggly and System.err:
"$date - OutputStream is full, discard previous logs"
| Property Name | Type | Description |
|---|---|---|
| inputKey | String | Loggly input key. "inputKey" or endpointUrl is required. Sample
"12345678-90ab-cdef-1234-567890abcdef" |
| endpointUrl | String | Loggly HTTP API endpoint URL. "inputKey" or endpointUrl is required. Sample:
"https://logs.loggly.com/inputs/12345678-90ab-cdef-1234-567890abcdef" |
| pattern | String | Pattern used for Loggly log messages. Default value is:
%d{"yyyy-MM-dd'T'HH:mm:ss.SSS'Z'",UTC} %-5level [%thread] %logger: %m%n. |
| proxyHost | String | hostname of a proxy server. If blank, no proxy is used (See URL.openConnection(java.net.Proxy). |
| proxyPort | int | port of a proxy server. Must be a valid int but is ignored if proxyHost is blank or null. |
| jmxMonitoring | boolean | Enable registration of a monitoring MBean named
"ch.qos.logback:type=LogglyBatchAppender,name=LogglyBatchAppender@#hashcode#". Default: true. |
| maxNumberOfBuckets | int | Max number of buckets of in the byte buffer. Default value: 8. |
| maxBucketSizeInKilobytes | int | Max size of each bucket. Default value: 1024 Kilobytes (1MB). |
| flushIntervalInSeconds | int | Interval of the buffer flush to Loggly API. Default value: 3. |
| connReadTimeoutSeconds | int | How Long the HTTP Connection will wait on reads. Default value: 1 second. |
flushIntervalInSeconds parameter to "2s" or event "1s".
<configuration scan="true" scanPeriod="30 seconds" debug="true">
<if condition='isDefined("logback.loggly.inputKey")'>
<then>
<appender name="loggly" class="ch.qos.logback.ext.loggly.LogglyBatchAppender">
<inputKey>${logback.loggly.inputKey}</inputKey>
<pattern>%d{yyyy/MM/dd HH:mm:ss,SSS} [${HOSTNAME}] [%thread] %-5level %logger{36} - %m %throwable{5}%n</pattern>
<proxyHost>${logback.loggly.proxy.host:-}</proxyHost>
<proxyPort>${logback.loggly.proxy.port:-8080}</proxyPort>
<debug>${logback.loggly.debug:-false}</debug>
</appender>
<root level="WARN">
<appender-ref ref="loggly"/>
</root>
</then>
</if>
</configuration>
ch.qos.logback.core.read.CyclicBufferAppender and buffering the ch.qos.logback.classic.spi.ILoggingEvent ?
Because it is much easier to control the size in memoryBufferedOutputStream on the HttpURLConnection ?
Because the Loggly API may not like such kind of streaming approach.
| Modifier and Type | Class and Description |
|---|---|
class |
LogglyBatchAppender.LogglyExporter |
| Modifier and Type | Field and Description |
|---|---|
static java.lang.String |
ENDPOINT_URL_PATH |
protected java.util.concurrent.atomic.AtomicLong |
sendDurationInNanos |
protected java.util.concurrent.atomic.AtomicInteger |
sendExceptionCount |
protected java.util.concurrent.atomic.AtomicInteger |
sendSuccessCount |
protected java.util.concurrent.atomic.AtomicLong |
sentBytes |
DEFAULT_ENDPOINT_PREFIX, DEFAULT_LAYOUT_PATTERN, endpointUrl, inputKey, layout, layoutCreatedImplicitly, proxy, UTF_8| Constructor and Description |
|---|
LogglyBatchAppender() |
| Modifier and Type | Method and Description |
|---|---|
protected void |
append(E eventObject) |
long |
getCurrentLogEntriesBufferSizeInBytes()
Size in bytes of the log entries that have not yet been sent to Loggly.
|
int |
getDiscardedBucketsCount()
Number of discarded buckets
|
protected java.lang.String |
getEndpointPrefix()
Returns the URL path prefix for the Loggly endpoint to which the
implementing class will send log events.
|
int |
getFlushIntervalInSeconds() |
protected java.net.HttpURLConnection |
getHttpConnection(java.net.URL url)
Creates a configured HTTP connection to a URL (does not open the
connection)
|
long |
getSendDurationInNanos()
Duration spent sending logs to Loggly.
|
int |
getSendExceptionCount()
Number of failing invocations to Loggly's send logs API.
|
int |
getSendSuccessCount()
Number of successful invocations to Loggly's send logs API.
|
long |
getSentBytes()
Number of bytes sent to Loggly.
|
boolean |
isDebug() |
void |
processLogEntries()
Send log entries to Loggly
|
protected void |
processLogEntries(java.io.InputStream in)
Send log entries to Loggly
|
void |
setConnReadTimeoutSeconds(int connReadTimeoutSeconds)
set method for Logback to allow Connection Read Timeout to be exposed
|
void |
setDebug(boolean debug)
Enable debugging
|
void |
setFlushIntervalInSeconds(int flushIntervalInSeconds) |
void |
setJmxMonitoring(boolean jmxMonitoring) |
void |
setMaxBucketSizeInKilobytes(int maxBucketSizeInKilobytes) |
void |
setMaxNumberOfBuckets(int maxNumberOfBuckets) |
void |
setMbeanServer(javax.management.MBeanServer mbeanServer) |
void |
start() |
void |
stop() |
buildEndpointUrl, createLayout, ensureLayout, getEndpointUrl, getHttpReadTimeoutInMillis, getInputKey, getLayout, getPattern, getProxyHost, getProxyPort, readResponseBody, setEndpointUrl, setHttpReadTimeoutInMillis, setInputKey, setLayout, setPattern, setProxyHost, setProxyPort, setProxyPort, toBytesaddFilter, clearAllFilters, doAppend, getCopyOfAttachedFiltersList, getFilterChainDecision, getName, isStarted, setName, toStringaddError, addError, addInfo, addInfo, addStatus, addWarn, addWarn, getContext, getDeclaredOrigin, getStatusManager, setContextpublic static final java.lang.String ENDPOINT_URL_PATH
protected final java.util.concurrent.atomic.AtomicLong sendDurationInNanos
protected final java.util.concurrent.atomic.AtomicLong sentBytes
protected final java.util.concurrent.atomic.AtomicInteger sendSuccessCount
protected final java.util.concurrent.atomic.AtomicInteger sendExceptionCount
protected void append(E eventObject)
append in class ch.qos.logback.core.UnsynchronizedAppenderBase<E>public void start()
start in interface ch.qos.logback.core.spi.LifeCyclestart in class AbstractLogglyAppender<E>public void stop()
stop in interface ch.qos.logback.core.spi.LifeCyclestop in class AbstractLogglyAppender<E>public void processLogEntries()
processLogEntries in interface LogglyBatchAppenderMBeanprotected java.net.HttpURLConnection getHttpConnection(java.net.URL url)
throws java.io.IOException
url - target URLjava.io.IOException - connection errorprotected void processLogEntries(java.io.InputStream in)
in - log input streampublic int getFlushIntervalInSeconds()
public void setFlushIntervalInSeconds(int flushIntervalInSeconds)
public long getSentBytes()
LogglyBatchAppenderMBeangetSentBytes in interface LogglyBatchAppenderMBeanpublic long getSendDurationInNanos()
LogglyBatchAppenderMBeangetSendDurationInNanos in interface LogglyBatchAppenderMBeanpublic int getSendSuccessCount()
LogglyBatchAppenderMBeangetSendSuccessCount in interface LogglyBatchAppenderMBeanpublic int getSendExceptionCount()
LogglyBatchAppenderMBeangetSendExceptionCount in interface LogglyBatchAppenderMBeanpublic int getDiscardedBucketsCount()
LogglyBatchAppenderMBeangetDiscardedBucketsCount in interface LogglyBatchAppenderMBeanpublic long getCurrentLogEntriesBufferSizeInBytes()
LogglyBatchAppenderMBeangetCurrentLogEntriesBufferSizeInBytes in interface LogglyBatchAppenderMBeanpublic void setDebug(boolean debug)
LogglyBatchAppenderMBeansetDebug in interface LogglyBatchAppenderMBeanpublic boolean isDebug()
isDebug in interface LogglyBatchAppenderMBeanpublic void setJmxMonitoring(boolean jmxMonitoring)
public void setMbeanServer(javax.management.MBeanServer mbeanServer)
public void setMaxNumberOfBuckets(int maxNumberOfBuckets)
public void setMaxBucketSizeInKilobytes(int maxBucketSizeInKilobytes)
public void setConnReadTimeoutSeconds(int connReadTimeoutSeconds)
protected java.lang.String getEndpointPrefix()
AbstractLogglyAppenderAbstractLogglyAppender.DEFAULT_ENDPOINT_PREFIX with the
endpoint prefix from AbstractLogglyAppender.getEndpointPrefix() and the
AbstractLogglyAppender.inputKey.getEndpointPrefix in class AbstractLogglyAppender<E>