一、前言
通过修改log4j的xml配置文件,打印mybatis的sql代码逻辑xml配置文件在代码执行过程具体sql上下文日志,log4j.xml默认配置如下>>
<?xml version="1.0" encoding="UTF-8"?>@b@<Configuration status="info">@b@ <Appenders>@b@ <Console name="CONSOLE" target="SYSTEM_OUT">@b@ <PatternLayout pattern="[%d{HH:mm:ss.SSS}] [%-3p] %x %c{1}: %m%n" />@b@ </Console>@b@ <Async name="Async">@b@ <AppenderRef ref="CONSOLE"/> @b@ </Async>@b@ </Appenders>@b@ <Loggers>@b@ <Root level="info" includeLocation="true">@b@ <AppenderRef ref="Async" />@b@ </Root> @b@ </Loggers>@b@</Configuration>
二、解决方法
在log4j.xml文件的Loggers节点追加dao包路径配置如下(com.xxx.xxx.dao是你项目的dao包路径)
<logger name="com.xxx.xxx.dao">@b@ <level>DEBUG</level>@b@</logger>
完整配置文件如下
<?xml version="1.0" encoding="UTF-8"?>@b@<Configuration status="info">@b@ <Appenders>@b@ <Console name="CONSOLE" target="SYSTEM_OUT">@b@ <PatternLayout pattern="[%d{HH:mm:ss.SSS}] [%-3p] %x %c{1}: %m%n" />@b@ </Console>@b@ <Async name="Async">@b@ <AppenderRef ref="CONSOLE"/> @b@ </Async>@b@ </Appenders>@b@ <Loggers>@b@ <Root level="info" includeLocation="true">@b@ <AppenderRef ref="Async" />@b@ </Root>@b@ <logger name="com.xxx.xxx.dao">@b@ <level>DEBUG</level>@b@ </logger>@b@ </Loggers>@b@</Configuration>