Help coderanch get a
new server
by contributing to the fundraiser
  • 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Devaka Cooray
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Tim Moores
  • Carey Brown
  • Mikalai Zaikin
Bartenders:
  • Lou Hamers
  • Piet Souris
  • Frits Walraven

How to define Log4j for multiple projects

 
Ranch Hand
Posts: 69
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi ,

I am using the following Log4j properties for 2 applications.
The first 'RF' is rootCategory and 'ASW' is rootLogger

I want RF to log into test-log.txt
And ASW to admin-log.txt

But it is logging both in admin-log.txt.

#### Use two appenders, one to log to console, another to log to a file

log4j.rootCategory=info, stdout, RF
log4j.rootLogger= info, stdout, ASW

#### First appender writes to console
log4j.appender.stdout=org.apache.log4j.ConsoleAppender
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout

# Pattern to output the caller's file name and line number.

log4j.appender.stdout.layout.ConversionPattern=[%d{ISO8601}]%5p%6.6r[%t]%x(%F:%L) - %m%n


#### Second appender writes to a file
log4j.appender.RF=org.apache.log4j.DailyRollingFileAppender
log4j.appender.RF.DatePattern='.'yyyy-MM-dd

log4j.appender.RF.File=C:/jrpapp1/wrk/log/weblog/test/test-log.txt
log4j.appender.RF.layout=org.apache.log4j.PatternLayout
log4j.appender.RF.layout.ConversionPattern=[%d{ISO8601}]%5p%6.6r[%t]%x(%F:%L) - %m%n

#### Third appender writes to a file
log4j.appender.ASW=org.apache.log4j.DailyRollingFileAppender
log4j.appender.ASW.DatePattern='.'yyyy-MM-dd

log4j.appender.ASW.File=C:/jrpapp1/wrk/log/weblog/admin/admin-log.txt
log4j.appender.ASW.layout=org.apache.log4j.PatternLayout
log4j.appender.ASW.layout.ConversionPattern=[%d{ISO8601}]%5p%6.6r[%t]%x(%F:%L) - %m%n




I am trying to test it the following test program

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

public class TestLog4j {

private static Logger log = Logger.getLogger(TestLog4j.class.getName());
private static Category cat = Category.getInstance(TestLog4j.class.getName());



public void testLog(){

log.info("Just testing ASW INFO");
cat.info("Just testing RF INFO");

}

public static void main(String[] args) {

TestLog4j tLog = new TestLog4j();
tLog.testLog();

}

}


Thanks,
Boon
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic