This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Other Open Source Projects and the fly likes Two different logs with single log4j.properties file Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Products » Other Open Source Projects
Bookmark "Two different logs with single log4j.properties file" Watch "Two different logs with single log4j.properties file" New topic
Author

Two different logs with single log4j.properties file

Ravii Varma
Greenhorn

Joined: Jun 17, 2012
Posts: 1
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.
Jeanne Boyarsky
internet detective
Marshal

Joined: May 26, 2003
Posts: 30136
    
150

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?


[Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Blogging on Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, OCAJP, OCPJP beta, TOGAF part 1 and part 2
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Two different logs with single log4j.properties file
 
Similar Threads
log4j - dailyrollingfileappender
log4j error
customize appenders within rootCategory
Log4j logs debug into info...
server could not started