Extracts, interpolates, formats and pretty prints SQL from datasource-proxy json logs.
- parses raw SLF4J logs using RegEx
- extracts and interpolates queries logged by datasource-proxy in JSON format
- formats the queries using sql-formatter
- highlights the queries using highlight.js
<dependency>
<groupId>net.ttddyy</groupId>
<artifactId>datasource-proxy</artifactId>
<version>1.7</version>
<scope>test</scope>
</dependency>
package my.app;
// imports skipped
@TestConfiguration
class DatasourceProxyConfig implements BeanPostProcessor {
@Override
public Object postProcessAfterInitialization(Object bean, String beanName) throws BeansException {
if (bean instanceof DataSource) {
return ProxyDataSourceBuilder
.create((DataSource) bean)
.name("dataSource-proxy")
.logQueryBySlf4j(SLF4JLogLevel.DEBUG)
.asJson()
.build();
}
return bean;
}
}
package my.app;
// imports skipped
@SpringBootTest(classes = {
Application.class,
DatasourceProxyConfig.class
})
@RunWith(SpringRunner.class)
@ActiveProfiles("integration")
public abstract class BaseIT {
// ...
}
# ...
logging:
level:
# Set SLF4JQueryLoggingListener log level to "debug" to enable Datasource Proxy Query logging
net.ttddyy.dsproxy.listener.logging.SLF4JQueryLoggingListener: off
# ...
For more configuration examples check datasource-proxy-examples