springboot+Druid+oracle 配置p6spy

p6spy可以将带参数的sql直接打出来方便调试。

1.gradle中引入

compile group: 'p6spy', name: 'p6spy', version: '3.8.1'

2.resources目录下增加spy.properties

module.log=com.p6spy.engine.logging.P6LogFactory,com.p6spy.engine.outage.P6OutageFactory
# 自定义日志打印
logMessageFormat=xxx.P6SpyLogger #自己实现的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=oracle.jdbc.OracleDriver
# 是否开启慢SQL记录
outagedetection=true
# 慢SQL记录标准 秒
outagedetectioninterval=2

3.P6SpyLogger   

public class P6SpyLogger implements MessageFormattingStrategy {
    @Override
    public String formatMessage(int connectionId, String now, long elapsed,
                                String category, String prepared, String sql, String url) {
        return !"".equals(sql.trim()) ? "| took "
                + elapsed + "ms | " + category + " | connection " + connectionId + "\n "
                + P6Util.singleLine(sql) + ";" : "";
    }
}

4.DruidConfig

public DataSource druidDataSource() throws Exception {
        DruidDataSource druidDataSource = new DruidDataSource();
        druidDataSource.setDriverClassName("oracle.jdbc.OracleDriver");
        druidDataSource.setDbType("oracle");
        .......
        return new P6DataSource(druidDataSource);
    }

 

转载于:https://www.cnblogs.com/liuboyuan/p/10289216.html

你可能感兴趣的:(springboot+Druid+oracle 配置p6spy)