我有一个“SomeClass”类,它有自己的log4j记录器。 在我的程序中,我的Someclass实例很少。 如何将Log4j配置为将日志专门输出到我班级的每个实例的唯一文件。
public class SomeClass {
private static Logger logger = Logger.getLogger(SomeClass.class);
private final String name;
public SomeClass(String name) throws Exception{
this.name = name;
}
}
public class MainClass{
public static void main(String[] args) throws Exception{
// logs generated by this instance should only go to a file AAA_YYYYMMDD.log
SomeClass instance1 = new SomeClass("AAA");
// logs generated by this instance should only go to a file BBB_YYYYMMDD.log
SomeClass instance2 = new SomeClass("BBB");
}
}