1、配置log4j的配置文件
#log4j.properties配置
=ALL, A1
.A1=org.apache.
.=C:/log4j/
.=.
.='.'yyyy-MM-dd-HH-mm
.=%-4r %-5p [%t] %37c %3x - %m%n
2、java中重新设置输出文件
import .;
import .;
public class SetLogFileName {
public SetLogFileName(String filename){
DailyRollingFileAppender appender = (DailyRollingFileAppender)().getAppender("A1");
( "c:/log4j/"+filename+".log");//动态地修改这个文件名
();
}
}
3、调用log4j输出文件
import .;
public class OutPutLog {
static Logger logger = ();
/**
* @param args
*/
public static void main(String[] args) {
SetLogFileName D = new SetLogFileName("trust");
// TODO Auto-generated method stub
("PIG");
}
}