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