Skip to content

Commit

Permalink
Merge pull request #7498 from Postremus/#3075-orm-bind-param-logging
Browse files Browse the repository at this point in the history
Add logging of hibernate orm bind params
  • Loading branch information
Sanne authored Mar 26, 2020
2 parents 8ae900c + 30c90a9 commit 8501c9f
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -284,14 +284,22 @@ public static class HibernateOrmConfigLog {
@ConfigItem(defaultValue = "false")
public boolean sql;

/**
* Logs SQL bind parameter.
* <p>
* Setting it to true is obviously not recommended in production.
*/
@ConfigItem(defaultValue = "false")
public boolean bindParam;

/**
* Whether JDBC warnings should be collected and logged.
*/
@ConfigItem(defaultValueDocumentation = "depends on dialect")
public Optional<Boolean> jdbcWarnings;

public boolean isAnyPropertySet() {
return sql || jdbcWarnings.isPresent();
return sql || bindParam || jdbcWarnings.isPresent();
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
import org.jboss.jandex.DotName;
import org.jboss.jandex.IndexView;
import org.jboss.jandex.Indexer;
import org.jboss.logmanager.Level;

import io.quarkus.agroal.deployment.JdbcDataSourceBuildItem;
import io.quarkus.agroal.deployment.JdbcDataSourceSchemaReadyBuildItem;
Expand All @@ -71,6 +72,7 @@
import io.quarkus.deployment.builditem.GeneratedResourceBuildItem;
import io.quarkus.deployment.builditem.HotDeploymentWatchedFileBuildItem;
import io.quarkus.deployment.builditem.LaunchModeBuildItem;
import io.quarkus.deployment.builditem.LogCategoryBuildItem;
import io.quarkus.deployment.builditem.SystemPropertyBuildItem;
import io.quarkus.deployment.builditem.nativeimage.NativeImageResourceBuildItem;
import io.quarkus.deployment.builditem.nativeimage.ReflectiveClassBuildItem;
Expand Down Expand Up @@ -716,6 +718,13 @@ private void handleHibernateORMWithNoPersistenceXml(
}
}

@BuildStep
public void produceLoggingCategories(BuildProducer<LogCategoryBuildItem> categories) {
if (hibernateConfig.log.bindParam) {
categories.produce(new LogCategoryBuildItem("org.hibernate.type.descriptor.sql.BasicBinder", Level.TRACE));
}
}

private Optional<String> guessDialect(Optional<String> dbKind) {
// For now select the latest dialect from the driver
// later, we can keep doing that but also avoid DCE
Expand Down

0 comments on commit 8501c9f

Please sign in to comment.