• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Junilu Lacar
  • Jeanne Boyarsky
  • Bear Bibeault
Sheriffs:
  • Knute Snortum
  • Tim Cooke
  • Devaka Cooray
Saloon Keepers:
  • Ron McLeod
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Piet Souris
  • Frits Walraven
  • Ganesh Patekar

Two different logs with single log4j.properties file

 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I'm trying to generate two different log files using single log4j.properties.

Log4j.properties:
log4j.appender.source1=DEBUG,sourceAppender1
log4j.additivity.source1=false
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.source2=DEBUG,sourceAppender2
log4j.additivity.source2=false
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.

Thanks,
Ravs.
 
author & internet detective
Posts: 39525
771
Eclipse IDE VI Editor Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ravs,
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?
 
Bring out your dead! Or a tiny ad:
Java file APIs (DOC, XLS, PDF, and many more)
https://products.aspose.com/total/java
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!