Pages

Thursday 10 April 2014

Logging in a clustered environment using Log4j

Logging using Socket Appender.

The logs should be stored in a centralized machine or sever when the application is stored in a clustered environment. Let’s get a scenario where every information level of logs goes in a clustered machine and error level log go in a server or centralized machine. So every cluster will have an information level log and if an error occurs it will show in a centralized machine.


There are four classes (Class1, Class2, Class3, Class4) these classes behave as a clustered application and ClassMain which contain the main method behave as a manager of this cluster. This cluster means class 1 2 3 4 will store the info level logs through RolingFileAppender, show the message in the console using ConsoleAppender and send the error level logs to a centralized machine using SocketAppender.

log4j.xml is the file which is defined in the application; every cluster will have the same property file and log4j-server.xml will be deployed in a centralized machine.

The command for starting socket server:-

java -classpath {Jar Path}\jars\log4j-1.2.17.jar org.apache.log4j.net.SimpleSocketServer
4712 {property file path}\log4j-server.properties 

References