Java Mailing List Archive

http://www.junlu.com/

Home » Home (12/2007) » J2EE Interest »

Help in log4j multiple out put files

Manoj Mallawaarachchie

2004-06-29





Dear All,


I have little problem with creating and separating log output to multiple log files,

I'm trying to do the separate log out put to files, but my problem is if do the instance one class in main program say A1.class instance A2.class

The logger define to A1.class contain A2.class es log out puts. So how can I avoid this.

Please give me some advice to overcome this issue. I attach my source files with this mail

Thank you,
Best regards,
Manoj


My config file
--------------------------------------------------------------------
#log4j.rootLogger=ALL, dest3, dest4


#Catagory
Log4j.category.dest4=INFO,dest4
Log4j.category.dest3=WARN,dest3

log4j.additivity.dest4=false
log4j.additivity.dest3=false


log4j.appender.dest4.layout=org.apache.log4j.PatternLayout
#WRITE LOG TO A FILE, ROLL THE FILE EVERY WEEK
log4j.appender.dest4=org.apache.log4j.DailyRollingFileAppender

# Specify the file name
log4j.appender.dest4.File=log2222.txt
# Control the maximum log file size
#log4j.appender.dest3.MaxFileSize=300KB

# Rollover log file at the start of each week
log4j.appender.dest4.DatePattern='.'yyyy-MM
log4j.appender.dest4.layout.ConversionPattern=%d{yyyy-MM-dd hh:mm:ss}

|%m %n
log4j.appender.dest4.Threshold=INFO


log4j.appender.dest3.layout=org.apache.log4j.PatternLayout
#WRITE LOG TO A FILE, ROLL THE FILE EVERY WEEK
log4j.appender.dest3=org.apache.log4j.DailyRollingFileAppender
# Specify the file name
log4j.appender.dest3.File=log.txt
# Control the maximum log file size
#log4j.appender.dest3.MaxFileSize=300KB
# Rollover log file at the start of each week
log4j.appender.dest3.DatePattern='.'yyyy-MM
log4j.appender.dest3.layout.ConversionPattern=%d{yyyy-MM-dd hh:mm:ss}

|%m %n
log4j.appender.dest3.Threshold=WARN
-----------------------------------------------------------------------

******Java main program  ******

import org.apache.log4j.Logger;
import org.apache.log4j.PropertyConfigurator;
import org.apache.log4j.Category;

public class dest3 {

  // static Logger logger = Logger.getLogger(getClass());

static Category  log = Category.getInstance(dest3.class.getClass());


   public static void main(String args[]) {

      PropertyConfigurator.configure("config3.txt");

    
      log.warn("Here is some FATAL");

dest4 d4 = new dest4();
/* This method out put should go to second log file, but it contain  2nd //logfile    as well as  this files(logfile 1)  too    */

d4.p();


   }
}
-------------------------------------

=========================================================================== To unsubscribe, send email to listserv@java.sun.com and include in the body of the message "signoff J2EE-INTEREST". For general help, send email to listserv@java.sun.com and include in the body of the message "help".

©2008 junlu.com - Jax Systems, LLC, U.S.A.