spring boot 和mybatis整合打印sql语句
- 工作小总结
- 时间:2017-11-10 15:22
- 9373人已阅读
简介
springboot默认的日志是logback.logback.xml如下:<?xml version="1.0" encoding="UTF-8"?><configuration scan="true" scanPeriod="30 seconds"
🔔🔔🔔好消息!好消息!🔔🔔🔔
有需要的朋友👉:联系凯哥
spring boot默认的日志是logback.
logback.xml如下:
<?xml version="1.0" encoding="UTF-8"?> <configuration scan="true" scanPeriod="30 seconds"> <appender name="console" class="ch.qos.logback.core.ConsoleAppender"> <encoder> <pattern>%-4relative [%thread] %-5level %logger{35} - %msg %n</pattern> </encoder> </appender> <appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender"> <!-- encoder 默认配置为PatternLayoutEncoder --> <encoder> <pattern>%d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n </pattern> </encoder> </appender> <appender name="logFile" class="ch.qos.logback.core.rolling.RollingFileAppender"> <file>${catalina.base}/logs/e-service.log</file> <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy"> <fileNamePattern>${catalina.base}/logs/e-service.%d{yyyy-MM-dd}.zip</fileNamePattern> <maxHistory>30</maxHistory> </rollingPolicy> <layout class="ch.qos.logback.classic.PatternLayout"> <Pattern>%d{HH:mm:ss.SSS} [%thread] %-5level %logger{40} - %msg%n</Pattern> </layout> </appender> <!-- <logger name="com.hengbao.fundcheck.repository" level="DEBUG"/> --> <!-- 以下这一句至关重要如果没有,就无法输出 sql 语句 --> <!--注意:在 spring boot 中,想在控制台打印 mybatis 的 sql 语句,只需要配置下边这一句就好了。--> <!--如果想要记录更详细的 SQL 日志,只需要把下面的日志级别改成 TRACE 就可以了--> <!--即将 mapper 接口打入 logger 就行。--> <logger name="com.kaigejava.project.mapper" level="DEBUG"/> <logger name="org.mybatis.spring" level="DEBUG" /> <logger name="org.apache.ibatis" level="DEBUG" /> <logger name="java.sql.PreparedStatement" level="DEBUG" /> <logger name="java.sql.Statement" level="DEBUG" /> <logger name="java.sql.Connection" level="DEBUG" /> <logger name="java.sql.ResultSet" level="DEBUG" /> <logger name="com.alibaba" level="INFO" /> <logger name="org.apache.commons" level="INFO" /> <logger name="org.apache.zookeeper" level="INFO" /> <logger name="org.springframework" level="INFO" /> <logger name="org.quartz" level="INFO" /> <root level="INFO"> <appender-ref ref="console" /> <appender-ref ref="logFile" /> <appender-ref ref="STDOUT" /> </root> </configuration>
说明:
<logger name="com.kaigejava.project.mapper" level="DEBUG"/>
这句很重要的。