使用BasicConfigurator定义基于包的日志记录

时间:2013-06-03 19:51:34

标签: log4j

我试图找出如何使用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 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);

1 个答案:

答案 0 :(得分:0)

我明白了。我不得不删除basicConfigurator.Configure!现在一切正常了