0

我试图弄清楚如何使用 BasicConfigurator 根据包分离我的日志文件,就像在我的 log4j.properties 中一样,我曾经有类似的附加程序

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

我尝试了以下方法,但似乎没有将请求分开到特定文件

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.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);
4

1 回答 1

0

我想到了。我不得不把 basicConfigurator.Configure 去掉!现在一切正常

于 2013-06-04T18:28:17.210 回答