Skip to content

Commit e6b428c

Browse files
committed
introduce ServiceLogger
1 parent a0643f2 commit e6b428c

File tree

6 files changed

+109
-55
lines changed

6 files changed

+109
-55
lines changed

hibernate-core/src/main/java/org/hibernate/boot/registry/classloading/internal/AggregatedServiceLoader.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
import java.util.ServiceLoader;
1616
import java.util.Set;
1717

18-
import static org.hibernate.internal.CoreMessageLogger.CORE_LOGGER;
18+
import static org.hibernate.service.internal.ServiceLogger.SERVICE_LOGGER;
1919

2020
/**
2121
* A service loader bound to an {@link AggregatedClassLoader}.
@@ -148,7 +148,7 @@ private boolean hasNextIgnoringServiceConfigurationError(Iterator<?> iterator) {
148148
return iterator.hasNext();
149149
}
150150
catch (ServiceConfigurationError e) {
151-
CORE_LOGGER.ignoringServiceConfigurationError( serviceContract.getName(), e );
151+
SERVICE_LOGGER.ignoringServiceConfigurationError( serviceContract.getName(), e );
152152
}
153153
}
154154
}

hibernate-core/src/main/java/org/hibernate/boot/registry/internal/BootstrapServiceRegistryImpl.java

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727

2828
import org.checkerframework.checker.nullness.qual.Nullable;
2929

30-
import static org.hibernate.internal.CoreMessageLogger.CORE_LOGGER;
30+
import static org.hibernate.service.internal.ServiceLogger.SERVICE_LOGGER;
3131

3232
/**
3333
* {@link ServiceRegistry} implementation containing specialized "bootstrap" services, specifically:<ul>
@@ -264,7 +264,7 @@ public synchronized <R extends Service> void stopService(ServiceBinding<R> bindi
264264
stoppable.stop();
265265
}
266266
catch ( Exception e ) {
267-
CORE_LOGGER.unableToStopService( binding.getServiceRole().getName(), e );
267+
SERVICE_LOGGER.unableToStopService( binding.getServiceRole().getName(), e );
268268
}
269269
}
270270
}
@@ -275,10 +275,7 @@ public synchronized void registerChild(ServiceRegistryImplementor child) {
275275
childRegistries = new HashSet<>();
276276
}
277277
if ( !childRegistries.add( child ) ) {
278-
CORE_LOGGER.warnf(
279-
"Child ServiceRegistry [%s] was already registered; this will end badly later...",
280-
child
281-
);
278+
SERVICE_LOGGER.childAlreadyRegistered( child );
282279
}
283280
}
284281

@@ -290,11 +287,11 @@ public synchronized void deRegisterChild(ServiceRegistryImplementor child) {
290287
childRegistries.remove( child );
291288
if ( childRegistries.isEmpty() ) {
292289
if ( autoCloseRegistry ) {
293-
CORE_LOGGER.trace( "Automatically destroying bootstrap registry after deregistration of every child ServiceRegistry" );
290+
SERVICE_LOGGER.destroyingBootstrapRegistry();
294291
destroy();
295292
}
296293
else {
297-
CORE_LOGGER.trace( "Skipping destroying bootstrap registry after deregistration of every child ServiceRegistry" );
294+
SERVICE_LOGGER.skippingBootstrapRegistryDestruction();
298295
}
299296
}
300297
}

hibernate-core/src/main/java/org/hibernate/internal/CoreMessageLogger.java

Lines changed: 21 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
import java.sql.SQLException;
1212
import java.sql.SQLWarning;
1313
import java.util.Properties;
14-
import java.util.ServiceConfigurationError;
1514
import java.util.Set;
1615

1716
import org.hibernate.HibernateException;
@@ -33,7 +32,6 @@
3332
import static org.jboss.logging.Logger.Level.DEBUG;
3433
import static org.jboss.logging.Logger.Level.ERROR;
3534
import static org.jboss.logging.Logger.Level.INFO;
36-
import static org.jboss.logging.Logger.Level.TRACE;
3735
import static org.jboss.logging.Logger.Level.WARN;
3836

3937
/**
@@ -44,7 +42,7 @@
4442
description = "Miscellaneous Logging related to Hibernate ORM Core"
4543
)
4644
@MessageLogger(projectCode = "HHH")
47-
@ValidIdRange(min=2,max = 20000)
45+
@ValidIdRange(min=2,max = 10000)
4846
@Internal
4947
public interface CoreMessageLogger extends BasicLogger {
5048

@@ -448,55 +446,44 @@ void cannotResolveNonNullableTransientDependencies(
448446
@Message(value = "Failed to discover types for enhancement from class: %s",
449447
id = 516)
450448
void enhancementDiscoveryFailed(String className, @Cause Throwable cause);
451-
452-
@LogMessage(level = ERROR)
453-
@Message(value = "Illegal argument on static metamodel field injection: %s#%s; expected type: %s; encountered type: %s", id = 15007)
454-
void illegalArgumentOnStaticMetamodelFieldInjection(
455-
String name,
456-
String name2,
457-
String name3,
458-
String name4);
459-
460-
@LogMessage(level = WARN)
461-
@Message(value = "Unable to locate static metamodel field: %s#%s; this may or may not indicate a problem with the static metamodel", id = 15011)
462-
void unableToLocateStaticMetamodelField(
463-
String name,
464-
String name2);
465-
466449
@LogMessage(level = DEBUG)
467450
@Message(
468-
id = 15015,
451+
id = 517,
469452
value = "Encountered a MappedSuperclass [%s] not used in any entity hierarchy"
470453
)
471454
void unusedMappedSuperclass(String name);
472455

473456
@LogMessage(level = WARN)
474457
@Message(
475-
id = 15018,
458+
id = 518,
476459
value = "Encountered multiple persistence-unit stanzas defining same name [%s]; persistence-unit names must be unique"
477460
)
478461
void duplicatedPersistenceUnitName(String name);
479462

480463
@LogMessage(level = WARN)
481464
@Message(
482-
id = 15019,
465+
id = 519,
483466
value = "Invalid JSON column type [%s], was expecting [%s]; for efficiency schema should be migrate to JSON DDL type"
484467
)
485468
void invalidJSONColumnType(String actual, String expected);
486469

487-
@LogMessage(level = TRACE)
488-
@Message(value = "Initializing service: %s", id = 500)
489-
void initializingService(String serviceRole);
490-
491-
@LogMessage(level = INFO)
492-
@Message(value = "Error stopping service: %s", id = 369)
493-
void unableToStopService(String serviceRole, @Cause Exception e);
494-
495-
@LogMessage(level = WARN)
496-
@Message(value = "Ignoring ServiceConfigurationError caught while instantiating service: %s", id = 505)
497-
void ignoringServiceConfigurationError(String serviceContract, @Cause ServiceConfigurationError error);
470+
@LogMessage(level = ERROR)
471+
@Message(
472+
id = 5001,
473+
value = "Illegal argument on static metamodel field injection: %s#%s; expected type: %s; encountered type: %s"
474+
)
475+
void illegalArgumentOnStaticMetamodelFieldInjection(
476+
String name,
477+
String name2,
478+
String name3,
479+
String name4);
498480

499481
@LogMessage(level = WARN)
500-
@Message(value = "Encountered request for service by non-primary service role [%s -> %s]", id = 450)
501-
void alternateServiceRole(String requestedRole, String targetRole);
482+
@Message(
483+
id = 5002,
484+
value = "Unable to locate static metamodel field: %s#%s; this may or may not indicate a problem with the static metamodel"
485+
)
486+
void unableToLocateStaticMetamodelField(
487+
String name,
488+
String name2);
502489
}

hibernate-core/src/main/java/org/hibernate/service/internal/AbstractServiceRegistryImpl.java

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232

3333
import org.checkerframework.checker.nullness.qual.Nullable;
3434

35-
import static org.hibernate.internal.CoreMessageLogger.CORE_LOGGER;
35+
import static org.hibernate.service.internal.ServiceLogger.SERVICE_LOGGER;
3636
import static org.hibernate.internal.util.config.ConfigurationHelper.getBoolean;
3737

3838
/**
@@ -158,14 +158,14 @@ protected void visitServiceBindings(Consumer<ServiceBinding<?>> action) {
158158
for ( var binding : serviceBindingMap.values() ) {
159159
if ( serviceRole.isAssignableFrom( binding.getServiceRole() ) ) {
160160
// we found an alternate...
161-
CORE_LOGGER.alternateServiceRole( serviceRole.getName(), binding.getServiceRole().getName() );
161+
SERVICE_LOGGER.alternateServiceRole( serviceRole.getName(), binding.getServiceRole().getName() );
162162
registerAlternate( serviceRole, binding.getServiceRole() );
163163
return (ServiceBinding<R>) binding;
164164
}
165165

166166
if ( binding.getService() != null && serviceRole.isInstance( binding.getService() ) ) {
167167
// we found an alternate...
168-
CORE_LOGGER.alternateServiceRole( serviceRole.getName(), binding.getServiceRole().getName() );
168+
SERVICE_LOGGER.alternateServiceRole( serviceRole.getName(), binding.getServiceRole().getName() );
169169
registerAlternate( serviceRole, binding.getServiceRole() );
170170
return (ServiceBinding<R>) binding;
171171
}
@@ -226,8 +226,8 @@ protected <R extends Service> void registerService(ServiceBinding<R> serviceBind
226226
}
227227

228228
private <R extends Service> @Nullable R initializeService(ServiceBinding<R> serviceBinding) {
229-
if ( CORE_LOGGER.isTraceEnabled() ) {
230-
CORE_LOGGER.initializingService( serviceBinding.getServiceRole().getName() );
229+
if ( SERVICE_LOGGER.isTraceEnabled() ) {
230+
SERVICE_LOGGER.initializingService( serviceBinding.getServiceRole().getName() );
231231
}
232232

233233
// PHASE 1: create service
@@ -294,7 +294,7 @@ private <R extends Service> void applyInjections(R service) {
294294
}
295295
}
296296
catch (NullPointerException e) {
297-
CORE_LOGGER.error( "NPE injecting service dependencies: " + service.getClass().getName() );
297+
SERVICE_LOGGER.error( "NPE injecting service dependencies: " + service.getClass().getName() );
298298
}
299299
}
300300

@@ -378,7 +378,7 @@ public synchronized <R extends Service> void stopService(ServiceBinding<R> bindi
378378
stoppable.stop();
379379
}
380380
catch ( Exception e ) {
381-
CORE_LOGGER.unableToStopService( binding.getServiceRole().getName(), e );
381+
SERVICE_LOGGER.unableToStopService( binding.getServiceRole().getName(), e );
382382
}
383383
}
384384
}
@@ -389,7 +389,7 @@ public synchronized void registerChild(ServiceRegistryImplementor child) {
389389
childRegistries = new HashSet<>();
390390
}
391391
if ( !childRegistries.add( child ) ) {
392-
CORE_LOGGER.warnf( "Child ServiceRegistry [%s] was already registered; this will end badly later", child );
392+
SERVICE_LOGGER.warnf( "Child ServiceRegistry [%s] was already registered; this will end badly later", child );
393393
}
394394
}
395395

@@ -401,11 +401,11 @@ public synchronized void deRegisterChild(ServiceRegistryImplementor child) {
401401
childRegistries.remove( child );
402402
if ( childRegistries.isEmpty() ) {
403403
if ( autoCloseRegistry ) {
404-
CORE_LOGGER.trace( "Automatically destroying ServiceRegistry after deregistration of every child ServiceRegistry" );
404+
SERVICE_LOGGER.trace( "Automatically destroying ServiceRegistry after deregistration of every child ServiceRegistry" );
405405
destroy();
406406
}
407407
else {
408-
CORE_LOGGER.trace( "Skipping destroying ServiceRegistry after deregistration of every child ServiceRegistry" );
408+
SERVICE_LOGGER.trace( "Skipping destroying ServiceRegistry after deregistration of every child ServiceRegistry" );
409409
}
410410
}
411411
}
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
/*
2+
* SPDX-License-Identifier: Apache-2.0
3+
* Copyright Red Hat Inc. and Hibernate Authors
4+
*/
5+
package org.hibernate.service.internal;
6+
7+
import org.hibernate.Internal;
8+
import org.hibernate.internal.SessionLogging;
9+
import org.hibernate.internal.log.SubSystemLogging;
10+
import org.hibernate.service.spi.ServiceRegistryImplementor;
11+
import org.jboss.logging.BasicLogger;
12+
import org.jboss.logging.Logger;
13+
import org.jboss.logging.annotations.Cause;
14+
import org.jboss.logging.annotations.LogMessage;
15+
import org.jboss.logging.annotations.Message;
16+
import org.jboss.logging.annotations.MessageLogger;
17+
import org.jboss.logging.annotations.ValidIdRange;
18+
19+
import java.lang.invoke.MethodHandles;
20+
import java.util.ServiceConfigurationError;
21+
22+
import static org.jboss.logging.Logger.Level.INFO;
23+
import static org.jboss.logging.Logger.Level.TRACE;
24+
import static org.jboss.logging.Logger.Level.WARN;
25+
26+
/**
27+
* Miscellaneous logging related to Hibernate ORM Core.
28+
*/
29+
@SubSystemLogging(
30+
name = SessionLogging.NAME,
31+
description = "Miscellaneous Logging related to Hibernate ORM Core"
32+
)
33+
@MessageLogger(projectCode = "HHH")
34+
@ValidIdRange(min=10002,max = 20000)
35+
@Internal
36+
public interface ServiceLogger extends BasicLogger {
37+
38+
String NAME = SubSystemLogging.BASE + ".service";
39+
40+
Logger LOGGER = Logger.getLogger( NAME );
41+
ServiceLogger SERVICE_LOGGER = Logger.getMessageLogger( MethodHandles.lookup(), ServiceLogger.class, NAME );
42+
43+
@LogMessage(level = TRACE)
44+
@Message(id = 10500, value = "Initializing service: %s")
45+
void initializingService(String serviceRole);
46+
47+
@LogMessage(level = INFO)
48+
@Message(id = 10369, value = "Error stopping service: %s")
49+
void unableToStopService(String serviceRole, @Cause Exception e);
50+
51+
@LogMessage(level = WARN)
52+
@Message(id = 10505, value = "Ignoring ServiceConfigurationError caught while instantiating service: %s")
53+
void ignoringServiceConfigurationError(String serviceContract, @Cause ServiceConfigurationError error);
54+
55+
@LogMessage(level = WARN)
56+
@Message(id = 10450, value = "Encountered request for service by non-primary service role [%s -> %s]")
57+
void alternateServiceRole(String requestedRole, String targetRole);
58+
59+
@LogMessage(level = WARN)
60+
@Message(id = 10451, value = "Child registry [%s] was already registered; this will end badly later...")
61+
void childAlreadyRegistered(ServiceRegistryImplementor child);
62+
63+
@LogMessage(level = TRACE)
64+
@Message(id = 10452, value = "Automatically destroying bootstrap registry after deregistration of every child ServiceRegistry")
65+
void destroyingBootstrapRegistry();
66+
67+
@LogMessage(level = TRACE)
68+
@Message(id = 10453, value = "Skipping destroying bootstrap registry after deregistration of every child ServiceRegistry")
69+
void skippingBootstrapRegistryDestruction();
70+
}

hibernate-core/src/test/java/org/hibernate/orm/test/jpa/persistenceunit/DuplicatePersistenceUnitNameTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ public class DuplicatePersistenceUnitNameTest extends BaseUnitTestCase {
3737
@Before
3838
public void setUp() {
3939
final Set messagesPrefixes = new HashSet<>();
40-
messagesPrefixes.add( "HHH015018" );
40+
messagesPrefixes.add( "HHH000518" );
4141
triggerable = logInspection.watchForLogMessages( messagesPrefixes );
4242
}
4343

0 commit comments

Comments
 (0)