|
Log4j 0.9.1 | |||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--org.log4j.AppenderSkeleton | +--org.log4j.net.SocketAppender
Sends LoggingEvent
objects to a remote a log server,
usually a SocketNode
.
The SocketAppender has the following properties:
SocketNode
, remote 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 by
the client.
LoggingEvent
object to the server side.
On the other hand, if the network link is up, but the server is down, the client will not be blocked when making log requests but the log events will be lost due to server unavailability.
SocketAppender
becomes
unreachable, it is automatically garbage collected if there the
connection to the server is up or if the
SocketAppender
instance is explicitly closed
. However, if the server is unreachable and the close
method is not called, then the SocketAppender
instance will not be garbage collected.
Long lived applications which create/destroy many
SocketAppender
instances should be aware of this
garbage collection problem. Most other applications can safely
ignore it.
SocketAppender
exits
before the SocketAppender
is closed either
explicitly or subsequent to garbage collection, then there might
be untransmitted data in the pipe which will be lost. This is
known problem on Windows based systems.
It is usually enough to close the SocketAppender
either explicitly or by removing it from the category where it
is attached and subsequently invoking System.gc()
to force garbage colection. See the code of
org.log4j.test.Shallow
for an example.
Field Summary | |
static String |
LOCATION_INFO_OPTION
A string constant used in naming the option for setting the the location information flag. |
static String |
PORT_OPTION
A string constant used in naming the option for setting the the port to contect on the remote server. |
static String |
RECONNECTION_DELAY_OPTION
A string constant used in naming the option for setting the delay between each reconneciton attempt to remote server. |
static String |
REMOTE_HOST_OPTION
A string constant used in naming the option for setting the the host name of the remote server. |
Fields inherited from class org.log4j.AppenderSkeleton |
closed, errorHandler, headFilter, layout, name, tailFilter, threshold, THRESHOLD_OPTION |
Constructor Summary | |
SocketAppender()
|
|
SocketAppender(InetAddress address,
int port)
Connects to remote server at address and port . |
|
SocketAppender(String host,
int port)
Connects to remote server at host and port . |
Method Summary | |
void |
activateOptions()
Connect to the specified RemoteHost and Port. |
void |
append(LoggingEvent event)
Subclasses of AppenderSkeleton should imlement this
method to perform actual logging. |
void |
cleanUp()
Drop the connection to the remote host and release the underlying connector thread if it has been created |
void |
close()
Close this appender. |
String[] |
getOptionStrings()
Retuns the option names for this component, namely the string array consisting of { REMOTE_HOST_OPTION , PORT_OPTION , LOCATION_INFO_OPTION , RECONNECTION_DELAY_OPTION } in addition to the options of its
super class AppenderSkeleton . |
boolean |
requiresLayout()
The SocketAppender does not use a layout. |
void |
setOption(String option,
String value)
Set SocketAppender specific options. |
Methods inherited from class org.log4j.AppenderSkeleton |
addFilter, clearFilters, doAppend, finalize, getErrorHandler, getFirstFilter, getName, isAsSevereAsThreshold, setErrorHandler, setLayout, setName, setThreshold |
Methods inherited from class java.lang.Object |
clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
public static final String REMOTE_HOST_OPTION
setOption(java.lang.String, java.lang.String)
method
for the meaning of this option.public static final String PORT_OPTION
setOption(java.lang.String, java.lang.String)
method
for the meaning of this option.public static final String LOCATION_INFO_OPTION
setOption(java.lang.String, java.lang.String)
method
for the meaning of this option.public static final String RECONNECTION_DELAY_OPTION
setOption(java.lang.String, java.lang.String)
method for the meaning of this option.Constructor Detail |
public SocketAppender()
public SocketAppender(InetAddress address, int port)
address
and port
.public SocketAppender(String host, int port)
host
and port
.Method Detail |
public void activateOptions()
activateOptions
in class AppenderSkeleton
public void close()
This will mark the appender as closed and
call then cleanUp()
method.
public void cleanUp()
public void append(LoggingEvent event)
AppenderSkeleton
AppenderSkeleton
should imlement this
method to perform actual logging. See also AppenderSkeleton.doAppend
method.append
in class AppenderSkeleton
public String[] getOptionStrings()
REMOTE_HOST_OPTION
, PORT_OPTION
, LOCATION_INFO_OPTION
, RECONNECTION_DELAY_OPTION
} in addition to the options of its
super class AppenderSkeleton
.getOptionStrings
in class AppenderSkeleton
public boolean requiresLayout()
false
.public void setOption(String option, String value)
On top of the options of the super class AppenderSkeleton
, the recognized options are RemoteHost,
Port and ReconnectionDelay, i.e. the values of the
string constants REMOTE_HOST_OPTION
, PORT_OPTION
,LOCATION_INFO_OPTION
and respectively RECONNECTION_DELAY_OPTION
.
The RemoteHost option takes a string value which should be
the host name of the server where a SocketNode
is running.
The Port option takes a positive integer representing the port where the server is waiting for connections.
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.
The ReconnectionDelay option takes a positive integer representing the number of milliseconds to wait between each failed connection attempt to the server. The default value of this option is 30000 which corresponds to 30 seconds.
setOption
in class AppenderSkeleton
|
Log4j 0.9.1 | |||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |