I am a beginner to log4j, and I seem to have understood the basics. My question is that I will be deploying my program on 2 different machines( client on machine 1 and server on machine 2 lets say), how would I be doing the logging then?
I have the following for now:
log4j.properties:
# Define the root logger with appender file
log4j.rootLogger = DEBUG, FILE
# Define the file appender
log4j.appender.FILE=org.apache.log4j.FileAppender
# Set the name of the file
log4j.appender.FILE.File=log.out
# Set the immediate flush to true (default)
log4j.appender.FILE.ImmediateFlush=true
# Set the threshold to debug mode
log4j.appender.FILE.Threshold=debug
# Set the append to false, overwrite
log4j.appender.FILE.Append=true
# Define the layout for file appender
log4j.appender.FILE.layout=org.apache.log4j.PatternLayout
log4j.appender.FILE.layout.conversionPattern=%m%n
log4jTest.java :
package ch.ethz.rama.asl.logger;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.Properties;
import org.apache.log4j.Logger;
import org.apache.log4j.PropertyConfigurator;
public class log4jTest {
static Logger log = Logger.getLogger(ch.ethz.rama.asl.client.ClientInstance.class);
public static void main(String args[]) throws FileNotFoundException, IOException{
Properties props = new Properties();
props.load(new FileInputStream("/Users/ramapriyasridharan/Documents/asl_v1/ClientServerNio/bin/log4j.properties"));
PropertyConfigurator.configure(props);
log.debug("debug");
log.info("info");
}
}
So should I have different logger objects for the client and server? Also if I want to append the same file on the client should I pass around the logger object using some method or should I create a new object? Im a little confused about this, thanks