1.pom.xml中引入log4j的依赖
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>1.2.17</version>
</dependency>
2.配置文件(mybatis-config.xml)中设置日志工厂为log4j
<settings>
<setting name="logImpl" value="LOG4J"/>
</settings>
4.log4j.properties
#将等级为DEBUG的日志信息输出到console和file这两个目的地,console和file的定义在下面代码
log4j.rootLogger=DEBUG,CONSOLE,file
# 输出控制台的相关设置
log4j.appender.CONSOLE=org.apache.log4j.ConsoleAppender
log4j.appender.CONSOLE.Target=System.out
log4j.appender.CONSOLE.Threshold=DEBUG
log4j.appender.CONSOLE.Encoding=UTF-8
log4j.appender.CONSOLE.layout=org.apache.log4j.PatternLayout
log4j.appender.CONSOLE.layout.ConversionPattern=[%c]-%m%n
### 文件输出的相关设置
log4j.appender.file = org.apache.log4j.RollingFileAppender
log4j.appender.file.File =./log/kuang.log
log4j.appender.file.MaxFileSize = 10mb
log4j.appender.file.Threshold = DEBUG
log4j.appender.file.layout = org.apache.log4j.PatternLayout
log4j.appender.file.layout.ConversionPattern = [%p]%d{yyyy-MM-dd HH:mm:ss}[%c]%m%n
###日志输出级别
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