用来给自己做笔记的,如果有帮到各位的,请帮我点个赞,谢谢。
首先是log4j2.xml文件,第一个OFF代表关闭状态,第二个OFF代表的是日志 的等级,常用的是debug,调试模式下打印sql语句等。
<?xml version="1.0" encoding="UTF-8"?>
<Configuration status="OFF">
<Appenders>
<Console name="Console" target="SYSTEM_OUT" follow="true">
<PatternLayout>
<pattern>%d %p %C{1.} [%t] %m%n</pattern>
</PatternLayout>
</Console>
<File name="File" fileName="log/log.txt">
<PatternLayout>
<pattern>%d %p %C{1.} [%t] %m%n </pattern>
</PatternLayout>
</File>
</Appenders>
<Loggers>
<!--debug info warn error fatal off all trace-->
<Root level="OFF">
<AppenderRef ref="Console" />
<!--<AppenderRef ref="File"/>-->
</Root>
</Loggers>
</Configuration>
然后要在mybatis-config.xml中配置一下log4j2
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE configuration PUBLIC "-//mybatis.org//DTD Config 3.0//EN" "http://mybatis.org/dtd/mybatis-3-config.dtd">
<configuration>
<settings>
<setting name="logImpl" value="log4j2"/>
</settings>
</configuration>
最后是spring.xml文件配置一下mybatis的配置文件的位置。在<bean></bean>里添加一行
<property name="configLocation" value="classpath:mybatis-config.xml"/>