Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

log4j - SocketAppender - java.io.EOFException

Status
Not open for further replies.

razor06

Programmer
Dec 11, 2008
1
US
I'm currently looking into doing asynchronous remote logging with log4j.
I've successfully implemented my AsyncAppender and tested it with the console appender, and now I'm trying to implement it with the SocketAppender, but I'm getting this error in the server log file:

code:


INFO (10 Dec 2008 10:29:11,303) [main] (SimpleSocketServer.java:60) - Listening on port 56564
INFO (10 Dec 2008 10:29:11,318) [main] (SimpleSocketServer.java:63) - Waiting to accept a new client.
INFO (10 Dec 2008 10:29:14,631) [main] (SimpleSocketServer.java:65) - Connected to client at /127.0.0.1
INFO (10 Dec 2008 10:29:14,631) [main] (SimpleSocketServer.java:66) - Starting new socket node.
INFO (10 Dec 2008 10:29:14,631) [main] (SimpleSocketServer.java:63) - Waiting to accept a new client.
INFO (10 Dec 2008 10:29:14,647) [Thread-0] (SocketNode.java:89) - Caught java.io.EOFException closing conneciton.



Here is my config file on the client:

code:


<log4j:configuration xmlns:log4j=" <appender name="async" class="org.apache.log4j.AsyncAppender">
<appender-ref ref="console" />
<appender-ref ref="socket" />
<param name="Blocking" value="false"/>
<param name="bufferSize" value="256"/>
</appender>

<appender name="socket" class="org.apache.log4j.net.SocketAppender">
<param name="Port" value="56564"/>
<param name="RemoteHost" value="localhost"/>
<param name="ReconnectionDelay" value="5000"/>
<param name="LocationInfo" value="true"/>
</appender>

<appender name="console" class="org.apache.log4j.ConsoleAppender">
<param name="Target" value="System.out"/>
<layout class="org.apache.log4j.PatternLayout">
<param name="ConversionPattern" value="%-5p %c{1} - %m%n"/>
</layout>
</appender>

<logger name="async.main.MainClass">
<param name="level" value="DEBUG"/>
</logger>

<root>
<param name="level" value="DEBUG"/>
<appender-ref ref="async" />
</root>

</log4j:configuration>



Here is my client test code:

code:


package async.main;

import org.apache.log4j.AsyncAppender;
import org.apache.log4j.LogManager;
import org.apache.log4j.Logger;
import org.apache.log4j.net.SocketAppender;
import org.apache.log4j.xml.DOMConfigurator;

public class MainClass {

private final static Logger log = Logger.getLogger(MainClass.class);

public static void main(String[] args) {
DOMConfigurator.configure("bin/configuration/log4j.xml");
try
{
log.info("hello world");
testLogger();
}
finally
{
AsyncAppender asyncAppender = (AsyncAppender)Logger.getRootLogger().getAppender("async");
if (asyncAppender != null)
{
SocketAppender socketAppender = (SocketAppender)asyncAppender.getAppender("socket");
if (socketAppender != null)
{
socketAppender.close();
LogManager.shutdown();
}
}
}
}

private static void testLogger()
{
log.error("This is a really bad error");
}

}



Now on the server side I'm running a very simple console app that's really just instanciating the log4j SimpleSocketServer implementation:

code:


package asyncServer;

import org.apache.log4j.net.SimpleSocketServer;

public class MainClass {

public static void main(String[] args) {
try
{
String[] arguments = {"56564", "bin/configuration/server.xml"};
SimpleSocketServer.main(arguments);
}
catch (Exception ex)
{

}
}
}



With the following config file associated to it:

code:


<log4j:configuration xmlns:log4j=" <appender name="rolling" class="org.apache.log4j.RollingFileAppender">
<layout class="org.apache.log4j.PatternLayout">
<param name="ConversionPattern" value="%5p (%d{DATE}) [%t] (%F:%L) - %m%n"/>
</layout>
<param name="File" value="bin/logs/async.log"/>
<param name="MaxFileSize" value="10KB"/>
<param name="MaxBackupIndex" value="5"/>
</appender>

<root>
<param name="level" value="DEBUG"/>
<appender-ref ref="rolling" />
</root>
</log4j:configuration>



Since log4j is very verbose, from the Eclipse console I've been able to verify that both config files, client and server, get picked up correctly.

I did find something interesting Googling around:

SimpleSocketServer BufferedIO issue

But that didn't help very much. Tried the suggestion and still getting the same error message.

Anyone successfully implemented AsyncAppender + SocketAppender with SimpleSocketServer by any chance?

Any idea if this is a "user" error or a problem with the SimpleSocketServer implementation? Any other SocketNode server implementation I could try out there?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top