使用 DruidDataSource 通过配置log4j.properties 在控制台打印 sql语句

这样配置就可以啦:

log4j.logger.druid.sql.ResultSet=INFO
log4j.logger.druid.sql.Connection=DEBUG
log4j.logger.druid.sql.DataSource=DEBUG
log4j.logger.druid.sql.Statement=DEBUG
log4j.logger.druid.sql.PreparedStatement=DEBUG 

完整的log4j.properties:

log4j.rootLogger=debug, stdout, flout

log4j.appender.stdout=org.apache.log4j.ConsoleAppender
log4j.appender.stdout.threshold=DEBUG
log4j.appender.stdout.Target=System.out
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
log4j.appender.stdout.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss} %5p %c{1}:%L - %m%n


log4j.logger.org.apache=INFO
log4j.logger.java.sql.ResultSet=INFO
log4j.logger.java.sql.Connection=DEBUG
log4j.logger.java.sql.Statement=DEBUG
log4j.logger.java.sql.PreparedStatement=DEBUG 


log4j.logger.druid.sql.ResultSet=INFO
log4j.logger.druid.sql.Connection=DEBUG
log4j.logger.druid.sql.DataSource=DEBUG
log4j.logger.druid.sql.Statement=DEBUG
log4j.logger.druid.sql.PreparedStatement=DEBUG 


log4j.appender.flout=org.apache.log4j.DailyRollingFileAppender
log4j.appender.flout.threshold=INFO
log4j.appender.flout.File=${catalina.home}/logs/my_logs_tomcat.log 
log4j.appender.logfile.Append=true
log4j.appender.flout.layout=org.apache.log4j.PatternLayout
log4j.appender.flout.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss} %5p %c{1}:%L - %m%n


你可能感兴趣的:(使用 DruidDataSource 通过配置log4j.properties 在控制台打印 sql语句)