Class SocketAppender
- java.lang.Object
-
- org.apache.logging.log4j.core.AbstractLifeCycle
-
- org.apache.logging.log4j.core.filter.AbstractFilterable
-
- org.apache.logging.log4j.core.appender.AbstractAppender
-
- org.apache.logging.log4j.core.appender.AbstractOutputStreamAppender<AbstractSocketManager>
-
- org.apache.logging.log4j.core.appender.SocketAppender
-
- All Implemented Interfaces:
Appender
,Filterable
,LocationAware
,LifeCycle
,LifeCycle2
- Direct Known Subclasses:
SyslogAppender
@Plugin(name="Socket", category="Core", elementType="appender", printObject=true) public class SocketAppender extends AbstractOutputStreamAppender<AbstractSocketManager>
An Appender that delivers events over socket connections. Supports both TCP and UDP.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
SocketAppender.AbstractBuilder<B extends SocketAppender.AbstractBuilder<B>>
Subclasses can extend this abstract Builder.static class
SocketAppender.Builder
Builds a SocketAppender.-
Nested classes/interfaces inherited from interface org.apache.logging.log4j.core.LifeCycle
LifeCycle.State
-
-
Field Summary
-
Fields inherited from class org.apache.logging.log4j.core.AbstractLifeCycle
DEFAULT_STOP_TIMEOUT, DEFAULT_STOP_TIMEUNIT, LOGGER
-
Fields inherited from interface org.apache.logging.log4j.core.Appender
ELEMENT_TYPE
-
-
Constructor Summary
Constructors Modifier Constructor Description protected
SocketAppender(String name, Layout<? extends Serializable> layout, Filter filter, AbstractSocketManager manager, boolean ignoreExceptions, boolean immediateFlush, Advertiser advertiser)
protected
SocketAppender(String name, Layout<? extends Serializable> layout, Filter filter, AbstractSocketManager manager, boolean ignoreExceptions, boolean immediateFlush, Advertiser advertiser, Property[] properties)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description static SocketAppender
createAppender(String host, int port, Protocol protocol, SslConfiguration sslConfig, int connectTimeoutMillis, int reconnectDelayMillis, boolean immediateFail, String name, boolean immediateFlush, boolean ignoreExceptions, Layout<? extends Serializable> layout, Filter filter, boolean advertise, Configuration configuration)
Deprecated.Deprecated in 2.7; usenewBuilder()
static SocketAppender
createAppender(String host, String portNum, String protocolIn, SslConfiguration sslConfig, int connectTimeoutMillis, String delayMillis, String immediateFail, String name, String immediateFlush, String ignore, Layout<? extends Serializable> layout, Filter filter, String advertise, Configuration config)
Deprecated.Deprecated in 2.5; usenewBuilder()
protected static AbstractSocketManager
createSocketManager(String name, Protocol protocol, String host, int port, int connectTimeoutMillis, SslConfiguration sslConfig, int reconnectDelayMillis, boolean immediateFail, Layout<? extends Serializable> layout, int bufferSize)
protected static AbstractSocketManager
createSocketManager(String name, Protocol protocol, String host, int port, int connectTimeoutMillis, SslConfiguration sslConfig, int reconnectDelayMillis, boolean immediateFail, Layout<? extends Serializable> layout, int bufferSize, SocketOptions socketOptions)
Creates an AbstractSocketManager for TCP, UDP, and SSL.protected void
directEncodeEvent(LogEvent event)
static SocketAppender.Builder
newBuilder()
boolean
stop(long timeout, TimeUnit timeUnit)
Cleanup the Filter.-
Methods inherited from class org.apache.logging.log4j.core.appender.AbstractOutputStreamAppender
append, getImmediateFlush, getManager, start, stop, writeByteArrayToManager
-
Methods inherited from class org.apache.logging.log4j.core.appender.AbstractAppender
error, error, error, getHandler, getLayout, getName, ignoreExceptions, parseInt, requiresLocation, setHandler, toSerializable, toString
-
Methods inherited from class org.apache.logging.log4j.core.filter.AbstractFilterable
addFilter, getFilter, getPropertyArray, hasFilter, isFiltered, removeFilter
-
Methods inherited from class org.apache.logging.log4j.core.AbstractLifeCycle
equalsImpl, getState, getStatusLogger, hashCodeImpl, initialize, isInitialized, isStarted, isStarting, isStopped, isStopping, setStarted, setStarting, setState, setStopped, setStopping, stop, stop
-
-
-
-
Constructor Detail
-
SocketAppender
protected SocketAppender(String name, Layout<? extends Serializable> layout, Filter filter, AbstractSocketManager manager, boolean ignoreExceptions, boolean immediateFlush, Advertiser advertiser, Property[] properties)
-
SocketAppender
@Deprecated protected SocketAppender(String name, Layout<? extends Serializable> layout, Filter filter, AbstractSocketManager manager, boolean ignoreExceptions, boolean immediateFlush, Advertiser advertiser)
-
-
Method Detail
-
newBuilder
@PluginBuilderFactory public static SocketAppender.Builder newBuilder()
-
stop
public boolean stop(long timeout, TimeUnit timeUnit)
Description copied from class:AbstractFilterable
Cleanup the Filter.- Specified by:
stop
in interfaceLifeCycle2
- Overrides:
stop
in classAbstractOutputStreamAppender<AbstractSocketManager>
- Parameters:
timeout
- the maximum time to waittimeUnit
- the time unit of the timeout argument- Returns:
- true if the receiver was stopped cleanly and normally, false otherwise.
-
createAppender
@Deprecated @PluginFactory public static SocketAppender createAppender(String host, int port, Protocol protocol, SslConfiguration sslConfig, int connectTimeoutMillis, int reconnectDelayMillis, boolean immediateFail, String name, boolean immediateFlush, boolean ignoreExceptions, Layout<? extends Serializable> layout, Filter filter, boolean advertise, Configuration configuration)
Deprecated.Deprecated in 2.7; usenewBuilder()
Creates a socket appender.- Parameters:
host
- The name of the host to connect to.port
- The port to connect to on the target host.protocol
- The Protocol to use.sslConfig
- The SSL configuration file for TCP/SSL, ignored for UPD.connectTimeoutMillis
- the connect timeout in milliseconds.reconnectDelayMillis
- The interval in which failed writes should be retried.immediateFail
- True if the write should fail if no socket is immediately available.name
- The name of the Appender.immediateFlush
- "true" if data should be flushed on each write.ignoreExceptions
- If"true"
(default) exceptions encountered when appending events are logged; otherwise they are propagated to the caller.layout
- The layout to use. Required, there is no default.filter
- The Filter or null.advertise
- "true" if the appender configuration should be advertised, "false" otherwise.configuration
- The Configuration- Returns:
- A SocketAppender.
-
createAppender
@Deprecated public static SocketAppender createAppender(String host, String portNum, String protocolIn, SslConfiguration sslConfig, int connectTimeoutMillis, String delayMillis, String immediateFail, String name, String immediateFlush, String ignore, Layout<? extends Serializable> layout, Filter filter, String advertise, Configuration config)
Deprecated.Deprecated in 2.5; usenewBuilder()
Creates a socket appender.- Parameters:
host
- The name of the host to connect to.portNum
- The port to connect to on the target host.protocolIn
- The Protocol to use.sslConfig
- The SSL configuration file for TCP/SSL, ignored for UPD.connectTimeoutMillis
- the connect timeout in milliseconds.delayMillis
- The interval in which failed writes should be retried.immediateFail
- True if the write should fail if no socket is immediately available.name
- The name of the Appender.immediateFlush
- "true" if data should be flushed on each write.ignore
- If"true"
(default) exceptions encountered when appending events are logged; otherwise they are propagated to the caller.layout
- The layout to use. Required, there is no default.filter
- The Filter or null.advertise
- "true" if the appender configuration should be advertised, "false" otherwise.config
- The Configuration- Returns:
- A SocketAppender.
-
createSocketManager
@Deprecated protected static AbstractSocketManager createSocketManager(String name, Protocol protocol, String host, int port, int connectTimeoutMillis, SslConfiguration sslConfig, int reconnectDelayMillis, boolean immediateFail, Layout<? extends Serializable> layout, int bufferSize)
Deprecated.Creates an AbstractSocketManager for TCP, UDP, and SSL.- Throws:
IllegalArgumentException
- if the protocol cannot be handled.
-
createSocketManager
protected static AbstractSocketManager createSocketManager(String name, Protocol protocol, String host, int port, int connectTimeoutMillis, SslConfiguration sslConfig, int reconnectDelayMillis, boolean immediateFail, Layout<? extends Serializable> layout, int bufferSize, SocketOptions socketOptions)
Creates an AbstractSocketManager for TCP, UDP, and SSL.- Throws:
IllegalArgumentException
- if the protocol cannot be handled.
-
directEncodeEvent
protected void directEncodeEvent(LogEvent event)
- Overrides:
directEncodeEvent
in classAbstractOutputStreamAppender<AbstractSocketManager>
-
-