1、配置log4j的配置文件
#log4j.properties配置
log4j.rootLogger=ALL, A1
log4j.appender.A1=org.apache.log4j.DailyRollingFileAppender
log4j.appender.A1.File=C:/log4j/TEST.log
log4j.appender.A1.layout=org.apache.log4j.PatternLayout
log4j.appender.A1.DatePattern='.'yyyy-MM-dd-HH-mm
log4j.appender.A1.layout.ConversionPattern=%-4r %-5p [%t] %37c %3x - %m%n
2、java中重新设置输出文件
import org.apache.log4j.DailyRollingFileAppender;
import org.apache.log4j.Logger;
public class SetLogFileName {
public SetLogFileName(String filename){
DailyRollingFileAppender appender = (DailyRollingFileAppender)Logger.getRootLogger().getAppender("A1");
appender.setFile( "c:/log4j/"+filename+".log");//动态地修改这个文件名