Using single output file for multiple Loggers
0 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   Jaweed_Iqbal
Posted On:   Wednesday, June 24, 2009 07:08 AM

I am having problem while using single output file for multiple Loggers. Contents of configuration file log4j.properties : log4j.rootLogger=DEBUG,root log4j.appender.root.layout=org.apache.log4j.PatternLayout log4j.appender.root.layout.ConversionPattern= %d %c %.5p : %m%n log4j.appender.root=org.apache.log4j.RollingFileAppender log4j.appender.root.File=EMPTY log4j.appender.root.MaxFileSize=20KB log4j.category.FirstLogger=DEBUG, FL log4j.appender.FL.layout=org.apache.log4j.PatternLayout log4j.appender.FL.layout.ConversionPattern= %d %c %.5p : %m%n    More>>

I am having problem while using single output file for multiple Loggers.



Contents of configuration file log4j.properties :



log4j.rootLogger=DEBUG,root


log4j.appender.root.layout=org.apache.log4j.PatternLayout


log4j.appender.root.layout.ConversionPattern= %d %c
%.5p : %m%n

log4j.appender.root=org.apache.log4j.RollingFileAppender


log4j.appender.root.File=EMPTY


log4j.appender.root.MaxFileSize=20KB

log4j.category.FirstLogger=DEBUG, FL

log4j.appender.FL.layout=org.apache.log4j.PatternLayout


log4j.appender.FL.layout.ConversionPattern= %d %c %.5p : %m%n


log4j.appender.FL.MaxBackupIndex=5


log4j.appender.FL=org.apache.log4j.RollingFileAppender

log4j.appender.FL.File=D:/TestLogging/Output.log

log4j.appender.FL.MaxFileSize=20KB

log4j.category.SecondLogger=DEBUG, SL

log4j.appender.SL.layout=org.apache.log4j.PatternLayout

log4j.appender.SL.layout.ConversionPattern= %d %c %.5p : %m%n

log4j.appender.SL.MaxBackupIndex=5

log4j.appender.SL=org.apache.log4j.RollingFileAppender

log4j.appender.SL.File=D:/TestLogging/Output.log

log4j.appender.SL.MaxFileSize=20KB




Test Program :



public class TestLogger {


public static void main(String args[]){


PropertyConfigurator.configure("D:/TestLogging/Log4j.properties");


Logger logger1 = Logger.getLogger("FirstLogger");


Logger logger2 = Logger.getLogger("SecondLogger");




for(int i=0; i <100; i++){


logger1.error(i+" : Testing Multiple Loggers..........");


}


for(int i=100; i <200; i++){


logger2.error(i+" : Testing Multiple Loggers..........");


}




for(int i=200; i <300; i++){


logger1.info(i+" : Testing Multiple Loggers..........");


}


for(int i=300; i <400; i++){


logger2.info(i+" : Testing Multiple Loggers..........");


}




for(int i=400; i <500; i++){


logger1.debug(i+" : Testing Multiple Loggers..........");


}


for(int i=500; i <600; i++){


logger2.debug(i+" : Testing Multiple
Loggers..........");


}



}


}





The problem is that when file size of Output.log reaches to MaxFileSize which is 20 KB, It does creates the backup file but owerrites the original log file.
Can anybody help why backup files are not getting created.

   <<Less
About | Sitemap | Contact