log4j打印mybatis日志

时间:2021-06-23 04:38:06

1 pom.xml添加引用:以下三个都要

<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId>
<version>1.7.25</version>
</dependency>
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>1.2.17</version>
</dependency>
<dependency>
<groupId>org.bgee.log4jdbc-log4j2</groupId>
<artifactId>log4jdbc-log4j2-jdbc4.1</artifactId>
<version>1.16</version>
</dependency>

2 设置mybatis的配置文件 mybatis-config.xml
<settings>
<!--打印日志到slf4j-->
<setting name="logImpl" value="SLF4J"></setting>
</settings>

3 log4j的属性要注意日志级别是DEBUG,尤其是下面第二句,我没注意将INFO修改成DEBUG,日志没打印出来
log4j.rootLogger=DEBUG,file
log4j.appender.file.Threshold=DEBUG