今天想做个小项目,用quartz启动两个自动作业,因为以后还要有很多自动作业要添加进来,所以考虑不把日志输出到一个文件,而是每个自动作业Log输出到独立的一个文件,每个自动作业放在不同的java包里,用包来配置log4j。问题来了,当我在 log4j.rootLogger 里配置两个不同包的log时,这两个log总是输出到自己以及到对方配置的文件里,如:
log4j.properties:
log4j.rootLogger=info, zeng.quartz , zeng.quartz2
log4j.appender.zeng.quartz=org.apache.log4j.DailyRollingFileAppender
log4j.appender.zeng.quartz.File=../quartzLog/log/log1.log
log4j.appender.zeng.quartz.MaxFileSize=10KB
log4j.appender.zeng.quartz.MaxBackupIndex=4
log4j.appender.zeng.quartz.layout=org.apache.log4j.PatternLayout
log4j.appender.zeng.quartz.DatePattern ='.'yyyy-MM-dd
log4j.appender.zeng.quartz.Threshold = DEBUG
log4j.appender.zeng.quartz.layout.ConversionPattern= %-d{yyyy-MM-dd HH:mm:ss} [ %t:%r ] - [ %p ] %m%n
#log4j.additivity.zeng.quartz=false
log4j.appender.zeng.quartz2=org.apache.log4j.DailyRollingFileAppender
log4j.appender.zeng.quartz2.File=../quartzLog/log/log2.log
log4j.appender.zeng.quartz2.MaxFileSize=10KB
log4j.appender.zeng.quartz2.MaxBackupIndex=4
log4j.appender.zeng.quartz2.layout=org.apache.log4j.PatternLayout
log4j.appender.zeng.quartz2.DatePattern ='.'yyyy-MM-dd
log4j.appender.zeng.quartz2.Threshold = DEBUG
log4j.appender.zeng.quartz2.layout.ConversionPattern=%-d{yyyy-MM-dd HH:mm:ss} [ %t:%r ] - [ %p ] %m%n
#log4j.additivity.zeng.quartz2=false
java:
package <span style="color:#FF0000;">zeng.quartz</span>;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileWriter;
import java.text.SimpleDateFormat;
import java.util.Date;
import org.apache.log4j.Logger;
/**
* @author Zeng 2016-4-24
*/
public class MyQuartz1 {
private transient static final Logger logger = Logger
.getLogger(MyQuartz1.class);
// private transient static final Logger logger = Logger
// .getLogger("zeng.quartz.MyQuartz1");
private static final String OUT_PATH = "C:\\Users\\Administrator\\Desktop\\QuartzLog.txt";
private static final String RN = "\n";
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
public void beginTask() throws Exception {
logger.info("Task MyQuartz1 begin!");
try {
File f = new File(OUT_PATH);
logger.info("File path: " + OUT_PATH