diff --git a/hibernate-core/src/main/java/org/hibernate/cfg/AvailableSettings.java b/hibernate-core/src/main/java/org/hibernate/cfg/AvailableSettings.java index 517cd11748..18834f59ee 100644 --- a/hibernate-core/src/main/java/org/hibernate/cfg/AvailableSettings.java +++ b/hibernate-core/src/main/java/org/hibernate/cfg/AvailableSettings.java @@ -2267,6 +2267,15 @@ public interface AvailableSettings { */ String GENERATE_STATISTICS = "hibernate.generate_statistics"; + /** + * Specifies a duration in milliseconds defining the minimum query execution time that + * characterizes a "slow" query. Any SQL query which takes longer than this amount of + * time to execute will be logged. + *

+ * A value of {@code 0}, the default, disables logging of "slow" queries. + */ + String LOG_SLOW_QUERY = "hibernate.log_slow_query"; + /** * Controls whether {@linkplain org.hibernate.stat.SessionStatistics session metrics} * should be {@linkplain org.hibernate.engine.internal.StatisticalLoggingSessionEventListener @@ -2277,15 +2286,6 @@ public interface AvailableSettings { */ String LOG_SESSION_METRICS = "hibernate.session.events.log"; - /** - * Specifies a duration in milliseconds defining the minimum query execution time that - * characterizes a "slow" query. Any SQL query which takes longer than this amount of - * time to execute will be logged. - *

- * A value of {@code 0}, the default, disables logging of "slow" queries. - */ - String LOG_SLOW_QUERY = "hibernate.session.events.log.LOG_QUERIES_SLOWER_THAN_MS"; - /** * Defines a default {@link org.hibernate.SessionEventListener} to be applied to * newly-opened {@link org.hibernate.Session}s. diff --git a/hibernate-core/src/main/java/org/hibernate/engine/jdbc/internal/SqlStatementLoggerInitiator.java b/hibernate-core/src/main/java/org/hibernate/engine/jdbc/internal/SqlStatementLoggerInitiator.java index 3615ed9e56..5e3218275c 100644 --- a/hibernate-core/src/main/java/org/hibernate/engine/jdbc/internal/SqlStatementLoggerInitiator.java +++ b/hibernate-core/src/main/java/org/hibernate/engine/jdbc/internal/SqlStatementLoggerInitiator.java @@ -9,27 +9,38 @@ import java.util.Map; import org.hibernate.boot.registry.StandardServiceInitiator; -import org.hibernate.cfg.Environment; import org.hibernate.engine.jdbc.spi.SqlStatementLogger; -import org.hibernate.internal.util.config.ConfigurationHelper; import org.hibernate.service.spi.ServiceRegistryImplementor; +import static org.hibernate.cfg.AvailableSettings.FORMAT_SQL; +import static org.hibernate.cfg.AvailableSettings.HIGHLIGHT_SQL; +import static org.hibernate.cfg.AvailableSettings.LOG_SLOW_QUERY; +import static org.hibernate.cfg.AvailableSettings.SHOW_SQL; +import static org.hibernate.internal.util.config.ConfigurationHelper.getBoolean; +import static org.hibernate.internal.util.config.ConfigurationHelper.getLong; + /** * The {@link SqlStatementLogger} is accessible via {@link org.hibernate.engine.jdbc.spi.JdbcServices}, - * but during service initialization, it might be needed before the {@code JdbcServices} service is initialized. - * - * For Hibernate Reactive + * but during service initialization, it might be needed before the {@code JdbcServices} service is + * initialized. */ public class SqlStatementLoggerInitiator implements StandardServiceInitiator { + // this deprecated property name never respected our conventions + private static final String OLD_LOG_SLOW_QUERY = "hibernate.session.events.log.LOG_QUERIES_SLOWER_THAN_MS"; + public static final SqlStatementLoggerInitiator INSTANCE = new SqlStatementLoggerInitiator(); @Override public SqlStatementLogger initiateService(Map configValues, ServiceRegistryImplementor registry) { - final boolean showSQL = ConfigurationHelper.getBoolean( Environment.SHOW_SQL, configValues ); - final boolean formatSQL = ConfigurationHelper.getBoolean( Environment.FORMAT_SQL, configValues ); - final boolean highlightSQL = ConfigurationHelper.getBoolean( Environment.HIGHLIGHT_SQL, configValues ); - final long logSlowQuery = ConfigurationHelper.getLong( Environment.LOG_SLOW_QUERY, configValues, 0 ); + final boolean showSQL = getBoolean( SHOW_SQL, configValues ); + final boolean formatSQL = getBoolean( FORMAT_SQL, configValues ); + final boolean highlightSQL = getBoolean( HIGHLIGHT_SQL, configValues ); + + long logSlowQuery = getLong( LOG_SLOW_QUERY, configValues, -2 ); + if ( logSlowQuery == -2 ) { + logSlowQuery = getLong( OLD_LOG_SLOW_QUERY, configValues, 0 ); + } return new SqlStatementLogger( showSQL, formatSQL, highlightSQL, logSlowQuery ); }