Class SocketHubAppender
- java.lang.Object
-
- org.apache.log4j.AppenderSkeleton
-
- org.apache.log4j.net.SocketHubAppender
-
- All Implemented Interfaces:
Appender,OptionHandler
public class SocketHubAppender extends AppenderSkeleton
SendsLoggingEventobjects to a set of remote log servers, usually aSocketNodes.Acts just like
SocketAppenderexcept that instead of connecting to a given remote log server,SocketHubAppenderaccepts 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 theSocketHubAppenderis running on.The
SocketHubAppenderdoes 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:
- If sent to a
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. SocketHubAppenderdoes not use a layout. It ships a serializedLoggingEventobject to the remote side.SocketHubAppenderrelies on the TCP protocol. Consequently, if the remote side is reachable, then log events will eventually arrive at remote client.- If no remote clients are attached, the logging requests are simply
dropped.
- Logging events are automatically buffered by the native TCP
implementation. This means that if the link to remote client is slow but
still faster than the rate of (log) event production, the application will
not be affected by the slow network connection. However, if the network
connection is slower then the rate of event production, then the local
application can only progress at the network rate. In particular, if the
network link to the the remote client is down, the application will be
blocked.
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.
- If the JVM hosting the
SocketHubAppenderexits before theSocketHubAppenderis 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()theSocketHubAppendereither explicitly or by calling theLogManager.shutdown()method before exiting the application.
- Author:
- Mark Womack
-
-
Field Summary
Fields Modifier and Type Field Description static java.lang.StringZONEThe MulticastDNS zone advertised by a SocketHubAppender-
Fields inherited from class org.apache.log4j.AppenderSkeleton
closed, errorHandler, headFilter, layout, name, tailFilter, threshold
-
-
Constructor Summary
Constructors Constructor Description SocketHubAppender()SocketHubAppender(int _port)Connects to remote server ataddressandport.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidactivateOptions()Set up the socket server on the specified port.voidappend(LoggingEvent event)Append an event to all of current connections.voidcleanUp()Release the underlying ServerMonitor thread, and drop the connections to all connected remote servers.voidclose()Close this appender.protected java.net.ServerSocketcreateServerSocket(int socketPort)Creates a server socket to accept connections.java.lang.StringgetApplication()Returns value of the Application option.intgetBufferSize()Returns value of the bufferSize option.booleangetLocationInfo()Returns value of the LocationInfo option.intgetPort()Returns value of the Port option.booleanisAdvertiseViaMulticastDNS()booleanrequiresLayout()The SocketHubAppender does not use a layout.voidsetAdvertiseViaMulticastDNS(boolean advertiseViaMulticastDNS)voidsetApplication(java.lang.String lapp)The App option takes a string value which should be the name of the application getting logged.voidsetBufferSize(int _bufferSize)The BufferSize option takes a positive integer representing the number of events this appender will buffer and send to newly connected clients.voidsetLocationInfo(boolean _locationInfo)The LocationInfo option takes a boolean value.voidsetPort(int _port)The Port option takes a positive integer representing the port where the server is waiting for connections.-
Methods inherited from class org.apache.log4j.AppenderSkeleton
addFilter, clearFilters, doAppend, finalize, getErrorHandler, getFilter, getFirstFilter, getLayout, getName, getThreshold, isAsSevereAsThreshold, setErrorHandler, setLayout, setName, setThreshold
-
-
-
-
Field Detail
-
ZONE
public static final java.lang.String ZONE
The MulticastDNS zone advertised by a SocketHubAppender- See Also:
- Constant Field Values
-
-
Method Detail
-
activateOptions
public void activateOptions()
Set up the socket server on the specified port.- Specified by:
activateOptionsin interfaceOptionHandler- Overrides:
activateOptionsin classAppenderSkeleton
-
close
public void close()
Close this appender.This will mark the appender as closed and call then
cleanUp()method.
-
cleanUp
public void cleanUp()
Release the underlying ServerMonitor thread, and drop the connections to all connected remote servers.
-
append
public void append(LoggingEvent event)
Append an event to all of current connections.- Specified by:
appendin classAppenderSkeleton
-
requiresLayout
public boolean requiresLayout()
The SocketHubAppender does not use a layout. Hence, this method returnsfalse.
-
setPort
public void setPort(int _port)
The Port option takes a positive integer representing the port where the server is waiting for connections.
-
setApplication
public void setApplication(java.lang.String lapp)
The App option takes a string value which should be the name of the application getting logged. If property was already set (via system property), don't set here.
-
getApplication
public java.lang.String getApplication()
Returns value of the Application option.
-
getPort
public int getPort()
Returns value of the Port option.
-
setBufferSize
public 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.
-
getBufferSize
public int getBufferSize()
Returns value of the bufferSize option.
-
setLocationInfo
public void setLocationInfo(boolean _locationInfo)
The LocationInfo option takes a boolean value. If true, the information sent to the remote host will include location information. By default no location information is sent to the server.
-
getLocationInfo
public boolean getLocationInfo()
Returns value of the LocationInfo option.
-
setAdvertiseViaMulticastDNS
public void setAdvertiseViaMulticastDNS(boolean advertiseViaMulticastDNS)
-
isAdvertiseViaMulticastDNS
public boolean isAdvertiseViaMulticastDNS()
-
createServerSocket
protected java.net.ServerSocket createServerSocket(int socketPort) throws java.io.IOExceptionCreates a server socket to accept connections.- Parameters:
socketPort- port on which the socket should listen, may be zero.- Returns:
- new socket.
- Throws:
java.io.IOException- IO error when opening the socket.
-
-