MyBatis - MyBatis使用log4j2显示sql和结果集
mybatis-config.xml
1 <settings> 2 <setting name="logImpl" value="LOG4J2" /> 3 </settings>
log4j2.xml
1 <?xml version="1.0" encoding="UTF-8"?> 2 <configuration status="OFF"> 3 <appenders> 4 <Console name="Console" target="SYSTEM_OUT"> 5 <PatternLayout pattern="%d{HH:mm:ss.SSS} [%t] %-5level %logger{36} - %msg%n"/> 6 </Console> 7 </appenders> 8 <loggers> 9 <logger name="log4j.logger.noModule" level="fatal" additivity="false"> 10 <appender-ref ref="Console"/> 11 </logger> 12 <logger name="log4j.logger.org.mybatis.jpetstore" level="trace" additivity="false"> 13 <appender-ref ref="Console"/> 14 </logger> 15 <logger name="log4j.logger.com.opensymphony.xwork2" level="debug" additivity="false"> 16 <appender-ref ref="Console"/> 17 </logger> 18 <logger name="log4j.logger.com.ibatis" level="trace" additivity="false"> 19 <appender-ref ref="Console"/> 20 </logger> 21 <logger name="log4j.logger.com.ibatis.common.jdbc.SimpleDataSource" level="debug" additivity="false"> 22 <appender-ref ref="Console"/> 23 </logger> 24 <logger name="log4j.logger.com.ibatis.common.jdbc.ScriptRunner" level="debug" additivity="false"> 25 <appender-ref ref="Console"/> 26 </logger> 27 <logger name="log4j.logger.com.ibatis.sqlmap.engine.impl.SqlMapClientDelegate" level="debug" additivity="false"> 28 <appender-ref ref="Console"/> 29 </logger> 30 <logger name="log4j.logger.org.mybatis" level="debug" additivity="false"> 31 <appender-ref ref="Console"/> 32 </logger> 33 <logger name="log4j.logger.java.sql" level="debug" additivity="false"> 34 <appender-ref ref="Console"/> 35 </logger> 36 <logger name="log4j.logger.java.sql.Connection" level="debug" additivity="false"> 37 <appender-ref ref="Console"/> 38 </logger> 39 <logger name="log4j.logger.java.sql.Statement" level="debug" additivity="false"> 40 <appender-ref ref="Console"/> 41 </logger> 42 <logger name="log4j.logger.java.sql.PreparedStatement" level="debug" additivity="false"> 43 <appender-ref ref="Console"/> 44 </logger> 45 <logger name="log4j.logger.java.sql.ResultSet" level="debug" additivity="false"> 46 <appender-ref ref="Console"/> 47 </logger> 48 <root level="trace"> 49 <appender-ref ref="Console"/> 50 </root> 51 </loggers> 52 </configuration>
接口说明:
待完善。