From f8379eefe1c605686c66d79ce4b7f67d044b74e5 Mon Sep 17 00:00:00 2001 From: Sven Strickroth Date: Mon, 24 Apr 2023 13:54:19 +0200 Subject: [PATCH] HHH-16507 Use subsystem logger instead of hard-coded "SQL dialect" Signed-off-by: Sven Strickroth --- .../org/hibernate/dialect/DialectLogging.java | 39 +++++++++++++++++++ .../dialect/internal/DialectFactoryImpl.java | 6 +-- .../hibernate/internal/CoreMessageLogger.java | 4 ++ 3 files changed, 45 insertions(+), 4 deletions(-) create mode 100644 hibernate-core/src/main/java/org/hibernate/dialect/DialectLogging.java diff --git a/hibernate-core/src/main/java/org/hibernate/dialect/DialectLogging.java b/hibernate-core/src/main/java/org/hibernate/dialect/DialectLogging.java new file mode 100644 index 0000000000..e630cacfcc --- /dev/null +++ b/hibernate-core/src/main/java/org/hibernate/dialect/DialectLogging.java @@ -0,0 +1,39 @@ +/* + * Hibernate, Relational Persistence for Idiomatic Java + * + * License: GNU Lesser General Public License (LGPL), version 2.1 or later + * See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html + */ +package org.hibernate.dialect; + +import org.hibernate.internal.log.SubSystemLogging; + +import org.jboss.logging.Logger; +import org.jboss.logging.annotations.LogMessage; +import org.jboss.logging.annotations.Message; +import org.jboss.logging.annotations.MessageLogger; +import org.jboss.logging.annotations.ValidIdRange; + +import static org.jboss.logging.Logger.Level.INFO; + +/** + * Logging related to Hibernate dialects + */ +@SubSystemLogging( + name = DialectLogging.LOGGER_NAME, + description = "Logging related to the dialects of SQL implemented by particular RDBMS" +) +@ValidIdRange( min = 35001, max = 36000) +@MessageLogger(projectCode = "HHH") +public interface DialectLogging { + String LOGGER_NAME = SubSystemLogging.BASE + ".dialect"; + Logger DIALECT_LOGGER = Logger.getLogger(LOGGER_NAME); + DialectLogging DIALECT_MESSAGE_LOGGER = Logger.getMessageLogger(DialectLogging.class, LOGGER_NAME); + + boolean DEBUG_ENABLED = DIALECT_LOGGER.isDebugEnabled(); + boolean TRACE_ENABLED = DIALECT_LOGGER.isTraceEnabled(); + + @LogMessage(level = INFO) + @Message(value = "Using dialect: %s", id = 35001) + void usingDialect(Dialect dialect); +} diff --git a/hibernate-core/src/main/java/org/hibernate/engine/jdbc/dialect/internal/DialectFactoryImpl.java b/hibernate-core/src/main/java/org/hibernate/engine/jdbc/dialect/internal/DialectFactoryImpl.java index 1c72b318cc..529e469416 100644 --- a/hibernate-core/src/main/java/org/hibernate/engine/jdbc/dialect/internal/DialectFactoryImpl.java +++ b/hibernate-core/src/main/java/org/hibernate/engine/jdbc/dialect/internal/DialectFactoryImpl.java @@ -15,12 +15,11 @@ import org.hibernate.boot.registry.selector.spi.StrategySelectionException; import org.hibernate.boot.registry.selector.spi.StrategySelector; import org.hibernate.cfg.AvailableSettings; import org.hibernate.dialect.Dialect; +import org.hibernate.dialect.DialectLogging; import org.hibernate.engine.jdbc.dialect.spi.DialectFactory; import org.hibernate.engine.jdbc.dialect.spi.DialectResolutionInfo; import org.hibernate.engine.jdbc.dialect.spi.DialectResolutionInfoSource; import org.hibernate.engine.jdbc.dialect.spi.DialectResolver; -import org.hibernate.internal.CoreLogging; -import org.hibernate.internal.CoreMessageLogger; import org.hibernate.internal.util.StringHelper; import org.hibernate.service.spi.ServiceRegistryAwareService; import org.hibernate.service.spi.ServiceRegistryImplementor; @@ -33,7 +32,6 @@ import static org.hibernate.internal.log.DeprecationLogger.DEPRECATION_LOGGER; * @author Steve Ebersole */ public class DialectFactoryImpl implements DialectFactory, ServiceRegistryAwareService { - private static final CoreMessageLogger LOG = CoreLogging.messageLogger( "SQL dialect" ); private static final Set LEGACY_DIALECTS = Set.of( "org.hibernate.community.dialect.DB297Dialect", "org.hibernate.community.dialect.DB2390Dialect", @@ -92,7 +90,7 @@ public class DialectFactoryImpl implements DialectFactory, ServiceRegistryAwareS } private static void logSelectedDialect(Dialect dialect) { - LOG.usingDialect( dialect ); + DialectLogging.DIALECT_MESSAGE_LOGGER.usingDialect( dialect ); Class dialectClass = dialect.getClass(); if ( dialectClass.isAnnotationPresent( Deprecated.class ) ) { diff --git a/hibernate-core/src/main/java/org/hibernate/internal/CoreMessageLogger.java b/hibernate-core/src/main/java/org/hibernate/internal/CoreMessageLogger.java index 5752436413..1149da2d22 100644 --- a/hibernate-core/src/main/java/org/hibernate/internal/CoreMessageLogger.java +++ b/hibernate-core/src/main/java/org/hibernate/internal/CoreMessageLogger.java @@ -1359,8 +1359,12 @@ public interface CoreMessageLogger extends BasicLogger { @Message(value = "Using default transaction strategy (direct JDBC transactions)", id = 399) void usingDefaultTransactionStrategy(); + /** + * @deprecated Use {@link org.hibernate.dialect.DialectLogging#usingDialect} instead + */ @LogMessage(level = INFO) @Message(value = "Using dialect: %s", id = 400) + @Deprecated void usingDialect(Dialect dialect); @LogMessage(level = ERROR)