in src/main/java/org/apache/log4j/net/SocketHubAppender.java [203:265]
void append(LoggingEvent event) {
if (event != null) {
// set up location info if requested
if (locationInfo) {
event.getLocationInformation();
}
if (application != null) {
event.setProperty("application", application);
}
event.getNDC();
event.getThreadName();
event.getMDCCopy();
event.getRenderedMessage();
event.getThrowableStrRep();
if (buffer != null) {
buffer.add(event);
}
}
// if no event or no open connections, exit now
if ((event == null) || (oosList.size() == 0)) {
return;
}
// loop through the current set of open connections, appending the event to each
for (int streamCount = 0; streamCount < oosList.size(); streamCount++) {
ObjectOutputStream oos = null;
try {
oos = (ObjectOutputStream)oosList.elementAt(streamCount);
}
catch (ArrayIndexOutOfBoundsException e) {
// catch this, but just don't assign a value
// this should not really occur as this method is
// the only one that can remove oos's (besides cleanUp).
}
// list size changed unexpectedly? Just exit the append.
if (oos == null)
break;
try {
oos.writeObject(event);
oos.flush();
// Failing to reset the object output stream every now and
// then creates a serious memory leak.
// right now we always reset. TODO - set up frequency counter per oos?
oos.reset();
}
catch(IOException e) {
if (e instanceof InterruptedIOException) {
Thread.currentThread().interrupt();
}
// there was an io exception so just drop the connection
oosList.removeElementAt(streamCount);
LogLog.debug("dropped connection");
// decrement to keep the counter in place (for loop always increments)
streamCount--;
}
}
}