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. |
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 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 |
|---|---|
protected AtomicLong |
sendDurationInNanos |
protected AtomicInteger |
sendExceptionCount |
protected AtomicInteger |
sendSuccessCount |
protected 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
|
int |
getFlushIntervalInSeconds() |
protected HttpURLConnection |
getHttpConnection(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(InputStream in)
Send log entries to Loggly
|
void |
setDebug(boolean debug)
Enable debugging
|
void |
setFlushIntervalInSeconds(int flushIntervalInSeconds) |
void |
setJmxMonitoring(boolean jmxMonitoring) |
void |
setMaxBucketSizeInKilobytes(int maxBucketSizeInKilobytes) |
void |
setMaxNumberOfBuckets(int maxNumberOfBuckets) |
void |
setMbeanServer(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, setContextprotected final AtomicLong sendDurationInNanos
protected final AtomicLong sentBytes
protected final AtomicInteger sendSuccessCount
protected final 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 HttpURLConnection getHttpConnection(URL url) throws IOException
url - target URLIOExceptionprotected void processLogEntries(InputStream in) throws IOException
IOExceptionpublic 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(MBeanServer mbeanServer)
public void setMaxNumberOfBuckets(int maxNumberOfBuckets)
public void setMaxBucketSizeInKilobytes(int maxBucketSizeInKilobytes)
Copyright © 2014. All Rights Reserved.