Win a copy of The Way of the Web Tester: A Beginner's Guide to Automating Tests this week in the Testing forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Two different logs with single file

Ravii Varma
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

I'm trying to generate two different log files using single
log4j.appender.sourceAppender1= org.apache.log4j.DailyRollingFileAppender
log4j.appender.sourceAppender1.DatePattern = '.'yyyy-MM-dd
log4j.appender.sourceAppender1.File = C:/sourceAppender1/logs/sourceAppender1.log
log4j.appender.sourceAppender1.layout = org.apache.log4j.PatternLayout
log4j.appender.sourceAppender1.layout.ConversionPattern = <%d{MMM dd}> %m%n

log4j.appender.sourceAppender2= org.apache.log4j.DailyRollingFileAppender
log4j.appender.sourceAppender2.DatePattern = '.'yyyy-MM-dd
log4j.appender.sourceAppender2.File = C:/sourceAppender2/logs/sourceAppender2.log;
log4j.appender.sourceAppender2.layout = org.apache.log4j.PatternLayout
log4j.appender.sourceAppender2.layout.ConversionPattern = <%d{MMM dd}> %m%n

Java code:
//For source1
Logger logr1 = Logger.getLogger("source1");
DailyRollingFileAppender drf1 = (DailyRollingFileAppender)logr1.getAppender(sourceAppender1);

//For source2
Logger logr2 = Logger.getLogger("source2");
DailyRollingFileAppender drf2 = (DailyRollingFileAppender)logr2.getAppender(sourceAppender2);

With this setting, log files are getting generated in both source folders, but with duplicate logs, both logs have data for both the sources, which I don't want to happen.
Please suggest, where I'm doing wrong.

Jeanne Boyarsky
author & internet detective
Posts: 35095
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to CodeRanch!

I think you are missing the part where you specify which package names go with which appender. See the section titled Appenders and Layouts. The tables show how they set up multiple appenders.

If this doesn't help, can you explain how you want to decide which logs go to which logger?
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic