### 1. 配置文件(已内置) ``` module.log=com.p6spy.engine.logging.P6LogFactory,com.p6spy.engine.outage.P6OutageFactory # 自定义日志打印 logMessageFormat=com.xiesx.springboot.core.logger.pkaq.P6SpyLogger # 使用日志系统记录sql appender=com.p6spy.engine.spy.appender.Slf4JLogger # 配置记录Log例外 excludecategories=info,debug,result,batc,resultset # 设置使用p6spy driver代理 deregisterdrivers=true # 日期格式 dateformat=yyyy-MM-dd HH:mm:ss # 实际驱动 driverlist=com.mysql.cj.jdbc.Driver # 是否开启慢SQL记录 outagedetection=true # 慢SQL记录标准 (秒) outagedetectioninterval=2 ``` ### 2.使用环境 实际使用中建议本地开发使用`p6spy` `application-local` ``` spring: datasource: driver-class-name: com.p6spy.engine.spy.P6SpyDriver url: jdbc:p6spy:mysql://127.0.0.1:3307/dbname?characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&autoReconnect=true&useSSL=false&serverTimezone=Asia/Shanghai username: xxxx password: xxxx ``` `application-release` ``` spring: datasource: driver-class-name: com.mysql.cj.jdbc.Driver url: jdbc:mysql://127.0.0.1:3307/dbname?characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&autoReconnect=true&useSSL=false&serverTimezone=Asia/Shanghai username: xxxx password: xxxx ``` ### 3. 验证打印 默认打印 ``` [FBOOT][ INFO][05-31 18:24:12]-->[http-nio-9090-exec-3:2007963][logSQL(Slf4JLogger.java:60)] | - | took 1ms | | statement | select * from sys_config where k=? ``` p6spy打印 ``` [FBOOT][ INFO][05-31 18:24:12]-->[http-nio-9090-exec-3:2007963][logSQL(Slf4JLogger.java:60)] | - | took 1ms | | statement | select * from sys_config where k='appUpdate' ```