Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ public ConnectionIdManagerProvider connectionIdManagerProvider() {
```
You can configure logging, query/slow query listeners and more using your `application.properties`:
> [!NOTE]
> Configuration below indicates al possible parameters together with their default values and **does not** need to be set explicitly
> Configuration below indicates all possible parameters together with their default values and **does not** need to be set explicitly
```properties
# One of logging libraries (slf4j, jul, common, sysout)
decorator.datasource.datasource-proxy.logging=slf4j
Expand All @@ -214,6 +214,14 @@ decorator.datasource.datasource-proxy.json-format=false
decorator.datasource.datasource-proxy.count-query=false
```

Optionally, configure a `LoggingFilter` to control the output of query logging:
```java
@Bean
public LoggingFilter loggingFilter() {
return MyLoggingFilter();
}
```

#### Flexy Pool

If the `flexy-pool-spring-boot-starter` is added to the classpath your datasource will be wrapped to the `FlexyPoolDataSource`.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import net.ttddyy.dsproxy.listener.QueryCountStrategy;
import net.ttddyy.dsproxy.listener.QueryExecutionListener;
import net.ttddyy.dsproxy.listener.logging.CommonsLogLevel;
import net.ttddyy.dsproxy.listener.logging.LoggingFilter;
import net.ttddyy.dsproxy.listener.logging.SLF4JLogLevel;
import net.ttddyy.dsproxy.proxy.ResultSetProxyLogicFactory;
import net.ttddyy.dsproxy.support.ProxyDataSourceBuilder;
Expand Down Expand Up @@ -70,6 +71,9 @@ public class ProxyDataSourceBuilderConfigurer {
@Autowired(required = false)
ProxyDataSourceBuilder.FormatQueryCallback formatQueryCallback;

@Autowired(required = false)
private LoggingFilter loggingFilter;

public void configure(ProxyDataSourceBuilder proxyDataSourceBuilder, DataSourceProxyProperties datasourceProxy) {
var query = datasourceProxy.getQuery();
var slowQuery = datasourceProxy.getSlowQuery();
Expand Down Expand Up @@ -126,6 +130,10 @@ public void configure(ProxyDataSourceBuilder proxyDataSourceBuilder, DataSourceP
log.warn("Found opposite format-sql and json format, json format will be used (may depend on library version)");
}

if (loggingFilter != null) {
proxyDataSourceBuilder.loggingFilter(loggingFilter);
}

if (datasourceProxy.isMultiline()) {
proxyDataSourceBuilder.multiline();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,12 @@
import net.ttddyy.dsproxy.QueryInfo;
import net.ttddyy.dsproxy.listener.ChainListener;
import net.ttddyy.dsproxy.listener.QueryExecutionListener;
import net.ttddyy.dsproxy.listener.logging.AbstractQueryLoggingListener;
import net.ttddyy.dsproxy.listener.logging.CommonsQueryLoggingListener;
import net.ttddyy.dsproxy.listener.logging.CommonsSlowQueryListener;
import net.ttddyy.dsproxy.listener.logging.JULQueryLoggingListener;
import net.ttddyy.dsproxy.listener.logging.JULSlowQueryListener;
import net.ttddyy.dsproxy.listener.logging.LoggingFilter;
import net.ttddyy.dsproxy.listener.logging.SLF4JQueryLoggingListener;
import net.ttddyy.dsproxy.listener.logging.SLF4JSlowQueryListener;
import net.ttddyy.dsproxy.listener.logging.SystemOutQueryLoggingListener;
Expand Down Expand Up @@ -227,6 +229,19 @@ void testCustomConnectionIdManager() {
});
}

@Test
void testCustomLoggingFilter() {
ApplicationContextRunner contextRunner = this.contextRunner.withUserConfiguration(CustomLoggingFilterConfiguration.class);

contextRunner.run(context -> {
DataSource dataSource = context.getBean(DataSource.class);
ProxyDataSource proxyDataSource = (ProxyDataSource) ((DecoratedDataSource) dataSource).getDecoratedDataSource();
LoggingFilter loggingFilter = context.getBean(LoggingFilter.class);
var queryListener = findListener(proxyDataSource, AbstractQueryLoggingListener.class);
assertThat(queryListener.getLoggingFilter()).isSameAs(loggingFilter);
});
}

@Configuration(proxyBeanMethods = false)
static class CustomDataSourceProxyConfiguration {

Expand Down Expand Up @@ -264,4 +279,13 @@ public void afterQuery(ExecutionInfo execInfo, List<QueryInfo> queryInfoList) {
};
}
}

@Configuration(proxyBeanMethods = false)
static class CustomLoggingFilterConfiguration {

@Bean
public LoggingFilter loggingFilter() {
return (execInfo, queryInfoList) -> true;
}
}
}
2 changes: 1 addition & 1 deletion gradle/libs.versions.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[versions]
spring-boot = "3.5.3"
p6Spy = "3.9.1"
datasource-proxy = "1.10.1"
datasource-proxy = "1.11.0"
flexy-pool = "3.0.2"

[libraries]
Expand Down
Loading