Log4j日志文件没有日志问题解决

现象:

tomcat启动后,登录日志都显示在tomcat的catalina.out里,没有打印在对应的项目的日志文件里

配置文件 :

logFilePath=/data/logs/Login-Interface/log.txt

log4j.rootLogger=DEBUG,A1

log4j.logger.com.mchange=ERROR,A2
log4j.logger.org=ERROR,A2
log4j.logger.httpclient.wire=ERROR,A2 
log4j.logger.net.spy=ERROR,A2
log4j.logger.com.opensymphony=ERROR,A2
log4j.logger.freemarker=ERROR,A2
log4j.category.com.jolbox=ERROR,A2

log4j.additivity.com.mchange=false
log4j.additivity.org.apache=false
log4j.additivity.httpclient.wire=false
log4j.additivity.net.spy=false
log4j.additivity.com.opensymphony=false
log4j.additivity.freemarker=false
log4j.additivity.TollResendLog=false
log4j.additivity.JmsLog=false

#######控制台
log4j.appender.A1=org.apache.log4j.ConsoleAppender 
log4j.appender.A1.layout=org.apache.log4j.PatternLayout 
log4j.appender.A1.layout.ConversionPattern=[%X{logid}][%-5p:%d{yyyy-MM-dd HH:mm:ss,SSS}:%l]%m%n
#log4j.appender.A1.layout.ConversionPattern=[%t][%-5p:%d{yyyy-MM-dd HH:mm:ss,SSS}:%l]%n%m%n
log4j.appender.A1.ImmediateFlush =true
#######文件
log4j.appender.A2=org.apache.log4j.DailyRollingFileAppender
log4j.appender.A2.File=${logFilePath}
#log4j.appender.A2.File=/usr/apache-tomcat-6.0.20/xiao/xiao.log
log4j.appender.A2.DatePattern='.'yyyy-MM-dd
log4j.appender.A2.layout=org.apache.log4j.PatternLayout
log4j.appender.A2.layout.ConversionPattern=[%X{logid}][%-5p:%d{yyyy-MM-dd HH:mm:ss,SSS}:%l]%m%n
#log4j.appender.A2.layout.ConversionPattern=[%t][%-5p:%d{yyyy-MM-dd HH:mm:ss,SSS}:%l]%n%m%n
log4j.appender.A2.encoding=utf-8
log4j.appender.A2.ImmediateFlush =true

解决:

因为A2才会执行把日志写入到文件 ,而log4j.rootLogger=DEBUG,A1只设置了A1,所以只有控制台会显示日志,文件没有日志

当我改成这样log4j.rootLogger=DEBUG,A1,A2,再重新执行就看到日志文件有日志了

上一篇:在Eclipse中使用log4j配置实例听


下一篇:Mybatis入门(七) 日志实现及分页处理