Fork me on GitHub

MyBatis笔记之配置输出日志并打印输出SQL语句

 

1. 引入Log4J的Maven依赖:

<dependency>
	<groupId>log4j</groupId>
	<artifactId>log4j</artifactId>
	<version>1.2.17</version>
</dependency>

 

2. 修改MyBatis的配置文件,设置使用Log4J日志输出方式:

<setting name="logImpl" value="STDOUT_LOGGING" />

如果是Spring Boot项目,则指定:

image

 

3. 在资源路径下新建log4j.properties:

log4j.rootLogger=DEBUG, Console  
#Console  
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.java.sql.ResultSet=INFO  
log4j.logger.org.apache=INFO  
log4j.logger.java.sql.Connection=DEBUG  
log4j.logger.java.sql.Statement=DEBUG  
log4j.logger.java.sql.PreparedStatement=DEBUG   

 

 

.

posted @ 2017-11-09 20:01  CC11001100  阅读(1564)  评论(0编辑  收藏  举报