Monday, May 2, 2011

Scala days 2011

The premier event for Scala enthusiasts, researchers, and practitioners Scala Days 2011 will be held at Stanford, California on the 2nd and 3rd of June 2011. Check out the official web site .

Saturday, March 19, 2011

Remote logging with Log4j

I'm writing about Log4j's Socket Appender. I can't just use and stay quiet. It's just really useful. So here is the case. You have a web application running in multiple instances behind a load balancer. Each server is going to have a log file and yes it's hard too track the log files down across multiple instances. If an instance is terminated you might even lose the log file. So we are gonna need a central log server that aggregates the log files to the central log server and this is done by log4j's Socket Appender.

I'll demonstrate it on my local computer but it would simply work for the case. I assume you have already installed and configured log4j for you application.

First we need to setup the log server. For this we use org.apache.log4j.net.SimpleSocketServer that can service multiple SocketAppender clients. SimpleSocketListener waits for logging events from SocketAppender clients. After reception the events are logged according to the server policy. It takes two parameters: port and configFile; where port is the port to listen on and configFile is configuration script in properties or XML format.