log4j向指定文件输出日志

一.log4j.properties中的配置

log4j.logger.cache=INFO,ERROR,batchFile
log4j.addivity.batchFile=false
log4j.appender.batchFile = org.apache.log4j.DailyRollingFileAppender
log4j.appender.batchFile.File =${catalina.home}/logs/front_batch
#log4j.appender.D.File =/eptms/eptms/log/logs/batch/front_batch
log4j.appender.batchFile.datePattern = yyyy-MM-dd'.log'
log4j.appender.batchFile.Append = true
#log4j.appender.D.Threshold = info
log4j.appender.batchFile.MaxBackupIndex=90
log4j.appender.batchFile.layout = org.apache.log4j.PatternLayout
log4j.appender.batchFile.layout.ConversionPattern =%d{yyyy-MM-dd HH\:mm\:ss} %5p [%c] (%L) - %m%n

二.java代码中的引用

public class TestDemo{
    
    //cache日志
  private static Log logger= LogFactory.getLog("cache");

  public void test(){
    logger.info("记录cache日志");  
  }
}

 

 

posted @ 2019-11-07 19:56  硝烟漫过十八岁  阅读(256)  评论(0编辑  收藏  举报