1. 程式人生 > >mybatis+log4j+springMvc 列印sql語句到控制檯

mybatis+log4j+springMvc 列印sql語句到控制檯

具體log4j.properties.配置 如下:

# Output pattern : date [thread] priority category - message   FATAL 0  ERROR 3  WARN 4  INFO 6  DEBUG 7 
log4j.rootLogger=DEBUG, Console, RollingFile


#Console
log4j.appender.Console=org.apache.log4j.ConsoleAppender
log4j.appender.Console.layout=org.apache.log4j.PatternLayout
log4j.appender.Console.layout.ConversionPattern=%d %-5p [%c{5}] - %m%n


#--------列印sql語句--------------------# 
#\u9996\u5148\u5C06rootLogger\u7EA7\u522B\u66F4\u6539\u4E3ADEBUG
#1 \u5B9A\u4E49\u65E5\u5FD7\u8F93\u51FA\u76EE\u7684\u5730\u4E3A\u63A7\u5236\u53F0


#\u63A7\u5236\u53F0\u6253\u5370sql\u8BED\u53E5
log4j.appender.Console.Target = System.out
log4j.appender.Console.Threshold=DEBUG


# mybatis \u663E\u793ASQL\u8BED\u53E5\u90E8\u5206
log4j.logger.org.mybatis=DEBUG
log4j.logger.java.sql=DEBUG
log4j.logger.java.sql.Statement=DEBUG
log4j.logger.java.sql.ResultSet=DEBUG
log4j.logger.java.sql.PreparedStatement=DEBUG
#--------------------------#


#RollingFile
log4j.appender.RollingFile=org.apache.log4j.DailyRollingFileAppender
log4j.appender.RollingFile.File=../logs/eoms/eoms.log
log4j.appender.RollingFile.layout=org.apache.log4j.PatternLayout
log4j.appender.RollingFile.layout.ConversionPattern=%d [%t] %-5p [%c] - %m%n


#log4j.logger.java.sql=DEBUG


#Springframework level
#log4j.logger.org.springframework=ERROR


#Hibernate level
#log4j.logger.org.hibernate=ERROR
#log4j.logger.org.hibernate.cache.ehcache.AbstractEhcacheRegionFactory=ERROR
#log4j.logger.org.hibernate.search.impl.ConfigContext=ERROR
#log4j.logger.net.sf.ehcache.config.CacheConfiguration=ERROR


#Project defalult level
#log4j.logger.org.activiti.engine.impl.persistence=DEBUG
#log4j.logger.org.apache.shiro=DEBUG
log4j.logger.com.thinkgem.jeesite=DEBUG
log4j.logger.com.thinkgem.jeesite.common.security.shiro=WARN
log4j.logger.JedisUtils=WARN
log4j.logger.LoginController=WARN
log4j.logger.OaNotifyDao.findCount=WARN

注意 要將log4j.rootLogger級別更改為debug