Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Log Agroal 'Connection acquired without transaction.' warning with stack trace right away #21832

Merged
merged 1 commit into from
Dec 1, 2021
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
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,14 @@ final class AgroalEventLoggingListener implements AgroalDataSourceListener {

private static final Logger log = Logger.getLogger("io.agroal.pool");

private static final String CONN_WITHOUT_TX = "Connection acquired without transaction.";

private final String datasourceName;
private final boolean transactionRequirementWarningActive;

public AgroalEventLoggingListener(String name) {
public AgroalEventLoggingListener(String name, boolean transactionRequirementWarningActive) {
this.datasourceName = "Datasource '" + name + "'";
this.transactionRequirementWarningActive = transactionRequirementWarningActive;
}

@Override
Expand Down Expand Up @@ -73,7 +77,11 @@ public void onInfo(String message) {

@Override
public void onWarning(Throwable throwable) {
log.warnv("{0}: {1}", datasourceName, throwable.getMessage());
log.debug("Cause: ", throwable);
if (transactionRequirementWarningActive && CONN_WITHOUT_TX.equals(throwable.getMessage())) {
log.warnv(throwable, "{0}", datasourceName);
} else {
log.warnv("{0}: {1}", datasourceName, throwable.getMessage());
log.debug("Cause: ", throwable);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import io.agroal.api.AgroalDataSource;
import io.agroal.api.AgroalPoolInterceptor;
import io.agroal.api.configuration.AgroalConnectionPoolConfiguration.ConnectionValidator;
import io.agroal.api.configuration.AgroalConnectionPoolConfiguration.TransactionRequirement;
import io.agroal.api.configuration.AgroalDataSourceConfiguration;
import io.agroal.api.configuration.AgroalDataSourceConfiguration.DataSourceImplementation;
import io.agroal.api.configuration.supplier.AgroalConnectionFactoryConfigurationSupplier;
Expand Down Expand Up @@ -186,7 +187,9 @@ public AgroalDataSource doCreateDataSource(String dataSourceName) {
// Explicit reference to bypass reflection need of the ServiceLoader used by AgroalDataSource#from
AgroalDataSourceConfiguration agroalConfiguration = dataSourceConfiguration.get();
AgroalDataSource dataSource = new io.agroal.pool.DataSource(agroalConfiguration,
new AgroalEventLoggingListener(dataSourceName));
new AgroalEventLoggingListener(dataSourceName,
agroalConfiguration.connectionPoolConfiguration()
.transactionRequirement() == TransactionRequirement.WARN));
log.debugv("Started datasource {0} connected to {1}", dataSourceName,
agroalConfiguration.connectionPoolConfiguration().connectionFactoryConfiguration().jdbcUrl());

Expand Down