public class SocketHubAppender extends AppenderSkeleton
LoggingEvent
objects to a set of remote log servers,
usually a SocketNodes
.
Acts just like SocketAppender
except that instead of
connecting to a given remote log server,
SocketHubAppender
accepts connections from the remote
log servers as clients. It can accept more than one connection.
When a log event is received, the event is sent to the set of
currently connected remote log servers. Implemented this way it does
not require any update to the configuration file to send data to
another remote log server. The remote log server simply connects to
the host and port the SocketHubAppender
is running on.
The SocketHubAppender
does not store events such
that the remote side will events that arrived after the
establishment of its connection. Once connected, events arrive in
order as guaranteed by the TCP protocol.
This implementation borrows heavily from the SocketAppender
.
The SocketHubAppender has the following characteristics:
SocketNode
, logging is non-intrusive as
far as the log event is concerned. In other words, the event will be
logged with the same time stamp, NDC
,
location info as if it were logged locally.
SocketHubAppender
does not use a layout. It
ships a serialized LoggingEvent
object to the remote side.
SocketHubAppender
relies on the TCP
protocol. Consequently, if the remote side is reachable, then log
events will eventually arrive at remote client.
On the other hand, if the network link is up, but the remote client is down, the client will not be blocked when making log requests but the log events will be lost due to client unavailability.
The single remote client case extends to multiple clients connections. The rate of logging will be determined by the slowest link.
SocketHubAppender
exits
before the SocketHubAppender
is closed either
explicitly or subsequent to garbage collection, then there might
be untransmitted data in the pipe which might be lost. This is a
common problem on Windows based systems.
To avoid lost data, it is usually sufficient to close()
the SocketHubAppender
either explicitly or by calling
the LogManager.shutdown()
method before
exiting the application.
限定符和类型 | 字段和说明 |
---|---|
static java.lang.String |
ZONE
The MulticastDNS zone advertised by a SocketHubAppender
|
closed, errorHandler, headFilter, layout, name, tailFilter, threshold
构造器和说明 |
---|
SocketHubAppender() |
SocketHubAppender(int _port)
Connects to remote server at
address and port . |
限定符和类型 | 方法和说明 |
---|---|
void |
activateOptions()
Set up the socket server on the specified port.
|
void |
append(LoggingEvent event)
Append an event to all of current connections.
|
void |
cleanUp()
Release the underlying ServerMonitor thread, and drop the connections
to all connected remote servers.
|
void |
close()
Close this appender.
|
protected java.net.ServerSocket |
createServerSocket(int socketPort)
Creates a server socket to accept connections.
|
java.lang.String |
getApplication()
Returns value of the Application option.
|
int |
getBufferSize()
Returns value of the bufferSize option.
|
boolean |
getLocationInfo()
Returns value of the LocationInfo option.
|
int |
getPort()
Returns value of the Port option.
|
boolean |
isAdvertiseViaMulticastDNS() |
boolean |
requiresLayout()
The SocketHubAppender does not use a layout.
|
void |
setAdvertiseViaMulticastDNS(boolean advertiseViaMulticastDNS) |
void |
setApplication(java.lang.String lapp)
The App option takes a string value which should be the name of the application getting logged.
|
void |
setBufferSize(int _bufferSize)
The BufferSize option takes a positive integer representing the number of events this appender will buffer and send to newly connected
clients.
|
void |
setLocationInfo(boolean _locationInfo)
The LocationInfo option takes a boolean value.
|
void |
setPort(int _port)
The Port option takes a positive integer representing
the port where the server is waiting for connections.
|
addFilter, clearFilters, doAppend, finalize, getErrorHandler, getFilter, getFirstFilter, getLayout, getName, getThreshold, isAsSevereAsThreshold, setErrorHandler, setLayout, setName, setThreshold
public static final java.lang.String ZONE
public SocketHubAppender()
public SocketHubAppender(int _port)
address
and port
.public void activateOptions()
activateOptions
在接口中 OptionHandler
activateOptions
在类中 AppenderSkeleton
public void close()
This will mark the appender as closed and
call then cleanUp()
method.
public void cleanUp()
public void append(LoggingEvent event)
append
在类中 AppenderSkeleton
public boolean requiresLayout()
false
.public void setPort(int _port)
public void setApplication(java.lang.String lapp)
public java.lang.String getApplication()
public int getPort()
public void setBufferSize(int _bufferSize)
public int getBufferSize()
public void setLocationInfo(boolean _locationInfo)
public boolean getLocationInfo()
public void setAdvertiseViaMulticastDNS(boolean advertiseViaMulticastDNS)
public boolean isAdvertiseViaMulticastDNS()
protected java.net.ServerSocket createServerSocket(int socketPort) throws java.io.IOException
socketPort
- port on which the socket should listen, may be zero.java.io.IOException
- IO error when opening the socket.