user2048598
user2048598

Reputation: 33

Define Logging Based on packages using BasicConfigurator

I am trying to figure out how to seperate my log files based on the packages using BasicConfigurator Like in my log4j.properties I used to have appenders like

log4j.logger.com.cambiahealth.engine.common.aspect=,memberservices
log4j.logger.com.cambiahealth.engine.rest.family=,familyservice

I tried the following but doesnt seem to seperate out the requests going to a particular file

FileAppender fa = new FileAppender();

fa.setName("abc");
fa.setFile("/usr/regence/mylog.log");
fa.setLayout(new PatternLayout("%d %-5p [%c{1}] %m%n"));
fa.setThreshold(Level.INFO);
fa.setAppend(true);
fa.activateOptions();
BasicConfigurator.configure(fa);
System.out.println("The logger abc is initialized");

Logger log= Logger.getLogger("com.cambiahealth.engine.rest.family"); log.addAppender(fa);

FileAppender xyz= new FileAppender();

xyz.setName("claims");
xyz.setFile("/usr/regence/myClaims.log");
xyz.setLayout(new PatternLayout("%d %-5p [%c{1}] %m%n"));
xyz.setThreshold(Level.INFO);
xyz.setAppend(true);
xyz.activateOptions();
BasicConfigurator.configure(claims);
System.out.println("The logger xyz is initialized");
BasicConfigurator.configure(xyz);
Logger.getLogger("com.xyz.claim").addAppender(xyz);

Upvotes: 0

Views: 118

Answers (1)

user2048598
user2048598

Reputation: 33

I figured it out. I had to removed the basicConfigurator.Configure out! and it all works now

Upvotes: 0

Related Questions