码迷,mamicode.com
首页 > 数据库 > 详细

jdbc打印sql语句-p6spy配置

时间:2019-12-22 10:48:50      阅读:84      评论:0      收藏:0      [点我收藏+]

标签:config   sso   过滤   文档   exe   span   set   lin   get   

@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配置

标签:config   sso   过滤   文档   exe   span   set   lin   get   

原文地址:https://www.cnblogs.com/hepengju/p/12078887.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!