logging-log4j-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From DanyLux <dany.gilgo...@gmail.com>
Subject Log4j over several java classes
Date Wed, 04 Nov 2009 12:21:43 GMT

Hello to all users,

I am new on Log4j.
I am doing a project in java with eclipse and my project has the following

                                    ----class4.java   <-- Applet

And some other information:
class4 calls class3 and class5
class2 is called by class1 and class1 called by class5.

In LogFile i have written the following:
public class LogFile {

	private static final String dirname  = "./log/"; //location of the log
	private static  Logger logger   = Logger.getRootLogger();

	 * This is the default constructor
	public LogFile() {
		try {
			PatternLayout layout = new PatternLayout( "%d (%c) [%t] %-5p %m%n" );
			DailyRollingFileAppender fileAppender =
				new DailyRollingFileAppender( layout, dirname + "Log.log",
"'.'yyyy-MM-dd" );
			logger.addAppender( fileAppender );
		} catch( Exception ex ) {
			System.err.println( ex );

	public void logError(String message){
                logger.info("Write several more information");

And so I called it on the several classes:
private static LogFile lfLogging = new LogFile();
lfLogging.logError("Error Message is written here!");

Well I entered it to all the class and the Logfile is written, the only
problem is when the method is called to write to logfile then it is not just
written once, but it is written 4 times the same. I commented in all class
just not in one the lines of logfile calling and then it just write once in
the LogFile.

Can somebody help me how I have to declare that my LogFile works correctly.

Many thanks in advance for your help.

Best regards,

View this message in context: http://old.nabble.com/Log4j-over-several-java-classes-tp26195319p26195319.html
Sent from the Log4j - Users mailing list archive at Nabble.com.

To unsubscribe, e-mail: log4j-user-unsubscribe@logging.apache.org
For additional commands, e-mail: log4j-user-help@logging.apache.org

View raw message