public abstract class AbstractLogstashTcpSocketAppender<Event extends ch.qos.logback.core.spi.DeferredProcessingAware> extends AsyncDisruptorAppender<Event>
AsyncDisruptorAppender appender that writes
events to a TCP Socket outputStream.
The behavior is similar to a ch.qos.logback.classic.net.SocketAppender, except that:
RingBuffer instead of a BlockingQueueEncoder instead of serialization
In addition, SSL can be enabled by setting the SSL configuration via setSsl(SSLConfiguration).
See the logback manual
for details on how to configure client-side SSL.
AsyncDisruptorAppender.LogEvent<Event>, AsyncDisruptorAppender.LogEventTranslator<Event>| Modifier and Type | Field and Description |
|---|---|
static int |
DEFAULT_CONNECTION_TIMEOUT
Default timeout when waiting for the remote server to accept our
connection.
|
static int |
DEFAULT_PORT
The default port number of remote logging server (4560).
|
static int |
DEFAULT_QUEUE_SIZE
Default size of the queue used to hold logging events that are destined
for the remote peer.
|
static int |
DEFAULT_RECONNECTION_DELAY
The default reconnection delay (30000 milliseconds or 30 seconds).
|
static String |
DEFAULT_THREAD_NAME_FORMAT |
static int |
DEFAULT_WRITE_BUFFER_SIZE |
protected static String |
HOST_NAME_FORMAT |
protected static String |
PORT_FORMAT |
APPENDER_NAME_FORMAT, DEFAULT_DROPPED_WARN_FREQUENCY, DEFAULT_PRODUCER_TYPE, DEFAULT_RING_BUFFER_SIZE, DEFAULT_WAIT_STRATEGY, THREAD_INDEX_FORMAT| Constructor and Description |
|---|
AbstractLogstashTcpSocketAppender() |
| Modifier and Type | Method and Description |
|---|---|
void |
addDestination(String destination)
Adds the given destination (or destinations) to the list of potential destinations
to which to send logs.
|
void |
addDestinations(InetSocketAddress... destinations)
Adds the given destinations to the list of potential destinations.
|
DestinationConnectionStrategy |
getConnectionStrategy() |
List<InetSocketAddress> |
getDestinations()
Return the destinations in which to attempt to send logs.
|
ch.qos.logback.core.encoder.Encoder<Event> |
getEncoder() |
protected String |
getHostString(InetSocketAddress destination)
Returns the host string from the given destination,
avoiding a DNS hit if possible.
|
Charset |
getKeepAliveCharset() |
ch.qos.logback.core.util.Duration |
getKeepAliveDuration() |
String |
getKeepAliveMessage() |
int |
getPort()
Deprecated.
|
int |
getQueueSize()
Returns the maximum number of events in the queue.
|
ch.qos.logback.core.util.Duration |
getReconnectionDelay() |
String |
getRemoteHost()
Deprecated.
|
ch.qos.logback.core.util.Duration |
getSecondaryConnectionTTL() |
SocketFactory |
getSocketFactory() |
ch.qos.logback.core.net.ssl.SSLConfiguration |
getSsl() |
protected List<Object> |
getThreadNameFormatParams() |
int |
getWriteBufferSize() |
boolean |
isKeepAliveEnabled() |
boolean |
isStarted() |
protected Future<?> |
scheduleReaderRunnable(Runnable readerRunnable) |
void |
setConnectionStrategy(DestinationConnectionStrategy destinationConnectionStrategy) |
void |
setEncoder(ch.qos.logback.core.encoder.Encoder<Event> encoder) |
void |
setKeepAliveCharset(Charset keepAliveCharset)
The charset to use when writing the
keepAliveMessage. |
void |
setKeepAliveDuration(ch.qos.logback.core.util.Duration keepAliveDuration)
If this duration elapses without an event being sent,
then the
keepAliveMessage will be sent to the socket in
order to keep the connection alive. |
void |
setKeepAliveMessage(String keepAliveMessage)
Message to send for keeping the connection alive
if
keepAliveDuration is non-null. |
void |
setPort(int port)
Deprecated.
use
addDestination(String) instead |
void |
setQueueSize(int queueSize)
Sets the maximum number of events in the queue.
|
void |
setReconnectionDelay(ch.qos.logback.core.util.Duration delay)
Time period for which to wait after failing to connect to all servers,
before attempting to reconnect.
|
void |
setRemoteHost(String host)
Deprecated.
use
addDestination(String) instead |
void |
setSecondaryConnectionTTL(ch.qos.logback.core.util.Duration secondaryConnectionTTL)
Convenience method for setting
PreferPrimaryDestinationConnectionStrategy.setSecondaryConnectionTTL(Duration). |
void |
setSocketFactory(SocketFactory socketFactory)
Used to create client
Sockets to which to communicate. |
void |
setSsl(ch.qos.logback.core.net.ssl.SSLConfiguration sslConfiguration)
Set this to non-null to use SSL.
|
void |
setThreadNameFormat(String threadNameFormat)
Pattern used by the to set the handler thread name.
|
void |
setWriteBufferSize(int writeBufferSize)
The number of bytes available in the write buffer.
|
void |
start() |
void |
stop() |
protected void |
updateCurrentThreadName() |
append, calculateThreadName, getDisruptor, getDroppedWarnFrequency, getEventHandler, getEventTranslator, getExecutorService, getProducerType, getRingBufferSize, getThreadFactory, getThreadNameFormat, getThreadNamePrefix, getThreadPoolCoreSize, getWaitStrategy, isDaemon, prepareForDeferredProcessing, setDaemon, setDroppedWarnFrequency, setEventFactory, setEventHandler, setEventTranslator, setProducerType, setRingBufferSize, setThreadFactory, setThreadNamePrefix, setThreadPoolCoreSize, setWaitStrategy, setWaitStrategyTypeaddFilter, clearAllFilters, doAppend, getCopyOfAttachedFiltersList, getFilterChainDecision, getName, setName, toStringaddError, addError, addInfo, addInfo, addStatus, addWarn, addWarn, getContext, getDeclaredOrigin, getStatusManager, setContextprotected static final String HOST_NAME_FORMAT
protected static final String PORT_FORMAT
public static final String DEFAULT_THREAD_NAME_FORMAT
public static final int DEFAULT_PORT
public static final int DEFAULT_RECONNECTION_DELAY
public static final int DEFAULT_QUEUE_SIZE
public static final int DEFAULT_CONNECTION_TIMEOUT
public static final int DEFAULT_WRITE_BUFFER_SIZE
public boolean isStarted()
isStarted in interface ch.qos.logback.core.spi.LifeCycleisStarted in class ch.qos.logback.core.UnsynchronizedAppenderBase<Event extends ch.qos.logback.core.spi.DeferredProcessingAware>public void start()
start in interface ch.qos.logback.core.spi.LifeCyclestart in class AsyncDisruptorAppender<Event extends ch.qos.logback.core.spi.DeferredProcessingAware>public void stop()
stop in interface ch.qos.logback.core.spi.LifeCyclestop in class AsyncDisruptorAppender<Event extends ch.qos.logback.core.spi.DeferredProcessingAware>public ch.qos.logback.core.encoder.Encoder<Event> getEncoder()
public void setEncoder(ch.qos.logback.core.encoder.Encoder<Event> encoder)
public SocketFactory getSocketFactory()
public void setSocketFactory(SocketFactory socketFactory)
Sockets to which to communicate.
By default, it is the system default SocketFactory.@Deprecated public void setRemoteHost(String host)
addDestination(String) instead@Deprecated public String getRemoteHost()
@Deprecated public void setPort(int port)
addDestination(String) instead@Deprecated public int getPort()
public void addDestination(String destination) throws IllegalArgumentException
The string is a comma separated list of destinations in the form of hostName[:portNumber].
If portNumber is not provided, then the configured port will be used,
which defaults to 4560
For example, "host1.domain.com,host2.domain.com:5560"
IllegalArgumentExceptionpublic void addDestinations(InetSocketAddress... destinations) throws IllegalArgumentException
IllegalArgumentException@IgnoreJRERequirement protected String getHostString(InetSocketAddress destination)
protected void updateCurrentThreadName()
protected List<Object> getThreadNameFormatParams()
getThreadNameFormatParams in class AsyncDisruptorAppender<Event extends ch.qos.logback.core.spi.DeferredProcessingAware>public List<InetSocketAddress> getDestinations()
public void setReconnectionDelay(ch.qos.logback.core.util.Duration delay)
public ch.qos.logback.core.util.Duration getReconnectionDelay()
public void setSecondaryConnectionTTL(ch.qos.logback.core.util.Duration secondaryConnectionTTL)
PreferPrimaryDestinationConnectionStrategy.setSecondaryConnectionTTL(Duration).
When the connectionStrategy is a PreferPrimaryDestinationConnectionStrategy,
this will set its PreferPrimaryDestinationConnectionStrategy.setSecondaryConnectionTTL(Duration).public ch.qos.logback.core.util.Duration getSecondaryConnectionTTL()
public int getWriteBufferSize()
public void setWriteBufferSize(int writeBufferSize)
public int getQueueSize()
public void setQueueSize(int queueSize)
Must be a positive power of 2.
queueSize - the maximum number of entries in the queue.public ch.qos.logback.core.net.ssl.SSLConfiguration getSsl()
public void setSsl(ch.qos.logback.core.net.ssl.SSLConfiguration sslConfiguration)
public ch.qos.logback.core.util.Duration getKeepAliveDuration()
public void setKeepAliveDuration(ch.qos.logback.core.util.Duration keepAliveDuration)
keepAliveMessage will be sent to the socket in
order to keep the connection alive.
When null, no keepAlive messages will be sent.public String getKeepAliveMessage()
public void setKeepAliveMessage(String keepAliveMessage)
keepAliveDuration is non-null.
The following values have special meaning:
Any other value will be used as-is.
public boolean isKeepAliveEnabled()
public Charset getKeepAliveCharset()
public void setKeepAliveCharset(Charset keepAliveCharset)
keepAliveMessage.
Defaults to UTF-8.public void setThreadNameFormat(String threadNameFormat)
If you change the AsyncDisruptorAppender.threadFactory, then this
value may not be honored.
The string is a format pattern understood by Formatter.format(String, Object...).
Formatter.format(String, Object...) is used to
construct the actual thread name prefix.
The first argument (%1$s) is the string appender name.
The second argument (%2$d) is the numerical thread index.
The third argument (%3$s) is the string hostname of the currently connected destination.
The fourth argument (%4$d) is the numerical port of the currently connected destination.
Other arguments can be made available by subclasses.
setThreadNameFormat in class AsyncDisruptorAppender<Event extends ch.qos.logback.core.spi.DeferredProcessingAware>public DestinationConnectionStrategy getConnectionStrategy()
public void setConnectionStrategy(DestinationConnectionStrategy destinationConnectionStrategy)
Copyright © 2017. All Rights Reserved.