p6spy实现sql监控
1、依赖添加
<dependency>
<groupId>p6spy</groupId>
<artifactId>p6spy</artifactId>
<version>3.8.1</version>
</dependency>
2、修改jdbc url和驱动程序类名
驱动程序为:com.p6spy.engine.spy.P6SpyDriver
URL:
mysql: jdbc:p6spy:mysql://localhost:3306/employees
h2: jdbc:p6spy:h2:mem:testdb
3、配置文件spy.properties
# 单行日志
logMessageFormat=com.p6spy.engine.spy.appender.SingleLineFormat
# 使用Slf4J记录sql
appender=com.p6spy.engine.spy.appender.Slf4JLogger
# 是否开启慢SQL记录
outagedetection=true
# 慢SQL记录标准,单位秒
outagedetectioninterval=2
4、可自定义日志格式写一个Format类,修改配置文件:logMessageFormat