jdbc打印sql语句-p6spy配置

Posted 何亦冷

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了jdbc打印sql语句-p6spy配置相关的知识,希望对你有一定的参考价值。

@Configuration
public class P6SpyConfig {

    /**
     * P6数据源包装, 打印SQL语句
     */
    @Bean
    public P6DataSourceBeanPostProcessor p6DataSourceBeanPostProcessor() {
        return new P6DataSourceBeanPostProcessor();
    }

    class P6DataSourceBeanPostProcessor implements BeanPostProcessor, PriorityOrdered {
        @Override
        public Object postProcessBeforeInitialization(Object bean, String beanName) throws BeansException {
            return bean;
        }

        @Override
        public Object postProcessAfterInitialization(Object bean, String beanName) throws BeansException {
            if (bean instanceof DataSource) {
                return new P6DataSource((DataSource) bean);
            }
            return bean;
        }

        @Override
        public int getOrder() {
            return Ordered.LOWEST_PRECEDENCE;
        }
    }

}
# P6Spy的配置,参考官方文档
# 官方文档位置: http://p6spy.readthedocs.io/en/latest/configandusage.html#common-property-file-settings

# 基本设置, 定制化输出, 数据库日期,布尔设置
autoflush=false
dateformat=yyyy-MM-dd HH:mm:ss

appender=com.p6spy.engine.spy.appender.Slf4JLogger
logMessageFormat=com.p6spy.engine.spy.appender.CustomLineFormat
customLogMessageFormat=%(executionTime)ms | %(sqlSingleLine)

databaseDialectDateFormat=yyyy-MM-dd
databaseDialectTimestampFormat=yyyy-MM-dd HH:mm:ss
databaseDialectBooleanFormat=boolean

# 过滤不需要的SQL语句, 排除的语句类型
filter=true
exclude=
excludecategories=info,debug,result,resultset,batch,commit,rollback

以上是关于jdbc打印sql语句-p6spy配置的主要内容,如果未能解决你的问题,请参考以下文章

HIBERNATE怎样查看sql语句

mybatis-plus打印完整sql语句

mybatis-plus打印完整sql语句

mybatis-plus打印完整sql语句

P6SPY 3.0.0-rc-1 发布,SQL 语句拦截

怎么配置log4j 打印出sql语句