"SpringBoot2.0 Actual Combat" series-integrate p6spy to realize SQL print log function

Preface

The sql log printing function is very practical in development. If you directly copy the log sql to the database for execution, you can quickly find the problem. This function is also needed in recent projects, so record this article under the mark.

Integration

Introduce related dependencies

<!--p6spy 打印sql-->
<dependency>
    <groupId>com.github.gavlyukovskiy</groupId>
    <artifactId>p6spy-spring-boot-starter</artifactId>
    <version>1.6.2</version>
</dependency>

Write the spy.properties configuration file, here is my version.

modulelist=com.baomidou.mybatisplus.extension.p6spy.MybatisPlusLogFactory,com.p6spy.engine.outage.P6OutageFactory
# 自定义日志打印
logMessageFormat=com.baomidou.mybatisplus.extension.p6spy.P6SpyLogger
# 日志只输出到控制台,不会记录到日志文件
appender=com.baomidou.mybatisplus.extension.p6spy.StdoutLogger
# 使用日志系统记录
#appender=com.p6spy.engine.spy.appender.Slf4JLogger
# 设置 p6spy driver 代理
deregisterdrivers=true
# 取消JDBC URL前缀
useprefix=true
# 配置记录 Log 例外,可去掉的结果集有error,info,batch,debug,statement,commit,rollback,result,resultset.
excludecategories=info,debug,result,commit,resultset
# 日期格式
dateformat=yyyy-MM-dd HH:mm:ss
# 实际驱动可多个
#driverlist=org.h2.Driver
# 是否开启慢SQL记录
outagedetection=true
# 慢SQL记录标准 2 秒
outagedetectioninterval=2

# 是否开启日志过滤 默认false
filter=true

# 过滤 Log 时所包含的表名列表,以逗号分隔 默认为空
#include=
# 过滤 Log 时所排除的表名列表,以逗号分隔 默认为空
exclude= foreign_key_checks,variable_name,GET_LOCK,RELEASE_LOCK,flyway_schema_history,information_schema,FROM DUAL,@,SELECT DATABASE(),SELECT version(),SELECT 1,ACT_,QRTZ_

# 过滤 Log 时的 SQL 正则表达式名称  默认为空
#sqlexpression=

The enable switch is added in yml, and different configurations are different in different environments.

# p6spy sql打印
decorator:
  datasource:
    enabled: true # 是否启用

Test Results

Insert picture description here

Taken from my open source project cloud-plus: https://blog.csdn.net/HXNLYW/article/details/104635673

Guess you like

Origin blog.csdn.net/HXNLYW/article/details/109096643