首页 > 代码库 > Log4j打印纯sql日志

Log4j打印纯sql日志

web.xml
-------------------------------------------------------------------
<!-- 日志监听器 -->

<context-param>
    <param-name>log4jConfigLocation</param-name>
    <param-value>classpath:log4j.properties</param-value>
</context-param>

<context-param>
    <param-name>log4jRefreshInterval</param-name>
    <param-value>60000</param-value>
</context-param>

<listener>
    <listener-class>org.springframework.web.util.Log4jConfigListener</listener-class>
</listener>

 

log4j.properties
--------------------------------------------------------------------

# 设置根路径打印级别为debug
log4j.rootLogger=debug, Console  
  
# 定义appender
log4j.appender.Console=org.apache.log4j.ConsoleAppender  
log4j.appender.Console.layout=org.apache.log4j.PatternLayout  
log4j.appender.Console.layout.ConversionPattern=%d [%t] %-5p [%c] - %m%n  

# 过滤掉不必要的日志(控制台打印出的多余日志的包路径)
log4j.logger.org.apache=error
log4j.logger.org.springframework=error
log4j.logger.org.mybatis.spring=error
log4j.logger.net.sf=error
log4j.logger.com.alibaba.druid=error

# 打印出sql语句相关日志
log4j.logger.java.sql.ResultSet=error 
log4j.logger.java.sql.Connection=error  
log4j.logger.java.sql.Statement=debug
log4j.logger.java.sql.PreparedStatement=debug   

Log4j打印纯sql日志