improve the aesthetics of some quite ugly log messages

This commit is contained in:
Gavin 2023-05-13 21:24:12 +02:00 committed by Gavin King
parent bf580b9e72
commit ac83f3e62f
7 changed files with 68 additions and 49 deletions

View File

@ -48,7 +48,12 @@ public class JtaPlatformInitiator implements StandardServiceInitiator<JtaPlatfor
platform = getFallbackProvider( configurationValues, registry ); platform = getFallbackProvider( configurationValues, registry );
} }
LOG.usingJtaPlatform( platform != null ? platform.getClass().getName() : "null" ); if ( platform != null && !(platform instanceof NoJtaPlatform) ) {
LOG.usingJtaPlatform( platform.getClass().getName() );
}
else {
LOG.noJtaPlatform();
}
return platform; return platform;
} }

View File

@ -81,7 +81,7 @@ public interface CoreMessageLogger extends BasicLogger {
@Message(value = "On release of batch it still contained JDBC statements", id = 10) @Message(value = "On release of batch it still contained JDBC statements", id = 10)
void batchContainedStatementsOnRelease(); void batchContainedStatementsOnRelease();
@LogMessage(level = INFO) @LogMessage(level = DEBUG)
@Message(value = "Bytecode provider: %s", id = 21) @Message(value = "Bytecode provider: %s", id = 21)
void bytecodeProvider(String provider); void bytecodeProvider(String provider);
@ -91,7 +91,7 @@ public interface CoreMessageLogger extends BasicLogger {
void c3p0ProviderClassNotFound(String c3p0ProviderClassName); void c3p0ProviderClassNotFound(String c3p0ProviderClassName);
@LogMessage(level = WARN) @LogMessage(level = WARN)
@Message(value = "I/O reported cached file could not be found : %s : %s", id = 23) @Message(value = "I/O reported cached file could not be found: [%s]: %s", id = 23)
void cachedFileNotFound(String path, FileNotFoundException error); void cachedFileNotFound(String path, FileNotFoundException error);
@LogMessage(level = INFO) @LogMessage(level = INFO)
@ -187,7 +187,7 @@ public interface CoreMessageLogger extends BasicLogger {
// void deprecatedForceDescriminatorAnnotation(); // void deprecatedForceDescriminatorAnnotation();
@LogMessage(level = WARN) @LogMessage(level = WARN)
@Message(value = "DEPRECATED : use [%s] instead with custom [%s] implementation", id = 65) @Message(value = "DEPRECATED: use [%s] instead with custom [%s] implementation", id = 65)
void deprecatedUuidGenerator(String name, String name2); void deprecatedUuidGenerator(String name, String name2);
@LogMessage(level = INFO) @LogMessage(level = INFO)
@ -264,7 +264,7 @@ public interface CoreMessageLogger extends BasicLogger {
void exceptionInBeforeTransactionCompletionInterceptor(@Cause Throwable e); void exceptionInBeforeTransactionCompletionInterceptor(@Cause Throwable e);
@LogMessage(level = INFO) @LogMessage(level = INFO)
@Message(value = "Sub-resolver threw unexpected exception, continuing to next : %s", id = 89) @Message(value = "Sub-resolver threw unexpected exception, continuing to next: %s", id = 89)
void exceptionInSubResolver(String message); void exceptionInSubResolver(String message);
@LogMessage(level = ERROR) @LogMessage(level = ERROR)
@ -563,7 +563,7 @@ public interface CoreMessageLogger extends BasicLogger {
// void parameterPositionOccurredAsBothJpaAndHibernatePositionalParameter(Integer position); // void parameterPositionOccurredAsBothJpaAndHibernatePositionalParameter(Integer position);
@LogMessage(level = ERROR) @LogMessage(level = ERROR)
@Message(value = "Error parsing XML (%s) : %s", id = 196) @Message(value = "Error parsing XML: (%s) %s", id = 196)
void parsingXmlError( void parsingXmlError(
int lineNumber, int lineNumber,
String message); String message);
@ -576,7 +576,7 @@ public interface CoreMessageLogger extends BasicLogger {
String message); String message);
@LogMessage(level = ERROR) @LogMessage(level = ERROR)
@Message(value = "Warning parsing XML (%s) : %s", id = 198) @Message(value = "Warning parsing XML: (%s) %s", id = 198)
void parsingXmlWarning( void parsingXmlWarning(
int lineNumber, int lineNumber,
String message); String message);
@ -615,11 +615,11 @@ public interface CoreMessageLogger extends BasicLogger {
void propertiesLoaded(Properties maskOut); void propertiesLoaded(Properties maskOut);
@LogMessage(level = DEBUG) @LogMessage(level = DEBUG)
@Message(value = "hibernate.properties not found", id = 206) @Message(value = "'hibernate.properties' not found", id = 206)
void propertiesNotFound(); void propertiesNotFound();
@LogMessage(level = WARN) @LogMessage(level = WARN)
@Message(value = "Property %s not found in class but described in <mapping-file/> (possible typo error)", id = 207) @Message(value = "Property '%s' not found in class but described in <mapping-file/> (possible typo error)", id = 207)
void propertyNotFound(String property); void propertyNotFound(String property);
// @LogMessage(level = WARN) // @LogMessage(level = WARN)
@ -793,7 +793,7 @@ public interface CoreMessageLogger extends BasicLogger {
void stoppingService(); void stoppingService();
@LogMessage(level = INFO) @LogMessage(level = INFO)
@Message(value = "sub-resolver threw unexpected exception, continuing to next : %s", id = 257) @Message(value = "sub-resolver threw unexpected exception, continuing to next: %s", id = 257)
void subResolverException(String message); void subResolverException(String message);
@LogMessage(level = INFO) @LogMessage(level = INFO)
@ -805,7 +805,7 @@ public interface CoreMessageLogger extends BasicLogger {
void synchronizationAlreadyRegistered(Synchronization synchronization); void synchronizationAlreadyRegistered(Synchronization synchronization);
@LogMessage(level = ERROR) @LogMessage(level = ERROR)
@Message(value = "Exception calling user Synchronization [%s] : %s", id = 260) @Message(value = "Exception calling user Synchronization [%s]: %s", id = 260)
void synchronizationFailed( void synchronizationFailed(
Synchronization synchronization, Synchronization synchronization,
Throwable t); Throwable t);
@ -839,7 +839,7 @@ public interface CoreMessageLogger extends BasicLogger {
void typeDefinedNoRegistrationKeys(Object type); void typeDefinedNoRegistrationKeys(Object type);
@LogMessage(level = DEBUG) @LogMessage(level = DEBUG)
@Message(value = "Type registration key [%s] overrode previous key : %s", id = 270) @Message(value = "Type registration key [%s] overrode previous key: %s", id = 270)
void typeRegistrationKeyOverridesPrevious( void typeRegistrationKeyOverridesPrevious(
String key, String key,
Type old); Type old);
@ -855,7 +855,7 @@ public interface CoreMessageLogger extends BasicLogger {
@Cause NamingException e); @Cause NamingException e);
@LogMessage(level = WARN) @LogMessage(level = WARN)
@Message(value = "Error accessing type info result set : %s", id = 273) @Message(value = "Error accessing type info result set: %s", id = 273)
void unableToAccessTypeInfoResultSet(String string); void unableToAccessTypeInfoResultSet(String string);
@LogMessage(level = WARN) @LogMessage(level = WARN)
@ -966,7 +966,7 @@ public interface CoreMessageLogger extends BasicLogger {
void unableToCompleteSchemaValidation(@Cause SQLException e); void unableToCompleteSchemaValidation(@Cause SQLException e);
@LogMessage(level = WARN) @LogMessage(level = WARN)
@Message(value = "Unable to configure SQLExceptionConverter : %s", id = 301) @Message(value = "Unable to configure SQLExceptionConverter: %s", id = 301)
void unableToConfigureSqlExceptionConverter(HibernateException e); void unableToConfigureSqlExceptionConverter(HibernateException e);
@LogMessage(level = ERROR) @LogMessage(level = ERROR)
@ -976,7 +976,7 @@ public interface CoreMessageLogger extends BasicLogger {
@Cause Throwable e); @Cause Throwable e);
@LogMessage(level = WARN) @LogMessage(level = WARN)
@Message(value = "Unable to construct instance of specified SQLExceptionConverter : %s", id = 303) @Message(value = "Unable to construct instance of specified SQLExceptionConverter: %s", id = 303)
void unableToConstructSqlExceptionConverter(Throwable t); void unableToConstructSqlExceptionConverter(Throwable t);
@LogMessage(level = WARN) @LogMessage(level = WARN)
@ -994,7 +994,7 @@ public interface CoreMessageLogger extends BasicLogger {
void unableToCreateSchema(@Cause Exception e); void unableToCreateSchema(@Cause Exception e);
@LogMessage(level = WARN) @LogMessage(level = WARN)
@Message(value = "Could not deserialize cache file: %s : %s", id = 307) @Message(value = "Could not deserialize cache file [%s]: %s", id = 307)
void unableToDeserializeCache( void unableToDeserializeCache(
String path, String path,
SerializationException error); SerializationException error);
@ -1034,7 +1034,7 @@ public interface CoreMessageLogger extends BasicLogger {
void unableToExecuteBatch(Exception e, String sql ); void unableToExecuteBatch(Exception e, String sql );
@LogMessage(level = WARN) @LogMessage(level = WARN)
@Message(value = "Error executing resolver [%s] : %s", id = 316) @Message(value = "Error executing resolver [%s]: %s", id = 316)
void unableToExecuteResolver( void unableToExecuteResolver(
DialectResolver abstractDialectResolver, DialectResolver abstractDialectResolver,
String message); String message);
@ -1062,7 +1062,7 @@ public interface CoreMessageLogger extends BasicLogger {
void unableToInstantiateOptimizer(String type); void unableToInstantiateOptimizer(String type);
@LogMessage(level = WARN) @LogMessage(level = WARN)
@Message(value = "Unable to instantiate UUID generation strategy class : %s", id = 325) @Message(value = "Unable to instantiate UUID generation strategy class: %s", id = 325)
void unableToInstantiateUuidGenerationStrategy(Exception ignore); void unableToInstantiateUuidGenerationStrategy(Exception ignore);
@LogMessage(level = WARN) @LogMessage(level = WARN)
@ -1074,7 +1074,7 @@ public interface CoreMessageLogger extends BasicLogger {
void unableToLoadCommand(@Cause HibernateException e); void unableToLoadCommand(@Cause HibernateException e);
@LogMessage(level = WARN) @LogMessage(level = WARN)
@Message(value = "Unable to load/access derby driver class sysinfo to check versions : %s", id = 328) @Message(value = "Unable to load/access derby driver class sysinfo to check versions: %s", id = 328)
void unableToLoadDerbyDriver(String message); void unableToLoadDerbyDriver(String message);
@LogMessage(level = ERROR) @LogMessage(level = ERROR)
@ -1095,11 +1095,11 @@ public interface CoreMessageLogger extends BasicLogger {
void unableToLocateMBeanServer(); void unableToLocateMBeanServer();
@LogMessage(level = WARN) @LogMessage(level = WARN)
@Message(value = "Unable to locate requested UUID generation strategy class : %s", id = 334) @Message(value = "Unable to locate requested UUID generation strategy class: %s", id = 334)
void unableToLocateUuidGenerationStrategy(String strategyClassName); void unableToLocateUuidGenerationStrategy(String strategyClassName);
@LogMessage(level = WARN) @LogMessage(level = WARN)
@Message(value = "Unable to log SQLWarnings : %s", id = 335) @Message(value = "Unable to log SQLWarnings: %s", id = 335)
void unableToLogSqlWarnings(SQLException sqle); void unableToLogSqlWarnings(SQLException sqle);
@LogMessage(level = WARN) @LogMessage(level = WARN)
@ -1166,7 +1166,7 @@ public interface CoreMessageLogger extends BasicLogger {
void unableToReleaseBatchStatement(); void unableToReleaseBatchStatement();
@LogMessage(level = ERROR) @LogMessage(level = ERROR)
@Message(value = "Could not release a cache lock : %s", id = 353) @Message(value = "Could not release a cache lock: %s", id = 353)
void unableToReleaseCacheLock(CacheException ce); void unableToReleaseCacheLock(CacheException ce);
@LogMessage(level = INFO) @LogMessage(level = INFO)
@ -1174,7 +1174,7 @@ public interface CoreMessageLogger extends BasicLogger {
void unableToReleaseContext(String message); void unableToReleaseContext(String message);
@LogMessage(level = WARN) @LogMessage(level = WARN)
@Message(value = "Unable to release created MBeanServer : %s", id = 355) @Message(value = "Unable to release created MBeanServer: %s", id = 355)
void unableToReleaseCreatedMBeanServer(String string); void unableToReleaseCreatedMBeanServer(String string);
@LogMessage(level = INFO) @LogMessage(level = INFO)
@ -1204,7 +1204,7 @@ public interface CoreMessageLogger extends BasicLogger {
String message); String message);
@LogMessage(level = WARN) @LogMessage(level = WARN)
@Message(value = "Unable to retrieve type info result set : %s", id = 362) @Message(value = "Unable to retrieve type info result set: %s", id = 362)
void unableToRetrieveTypeInfoResultSet(String string); void unableToRetrieveTypeInfoResultSet(String string);
@LogMessage(level = INFO) @LogMessage(level = INFO)
@ -1212,7 +1212,7 @@ public interface CoreMessageLogger extends BasicLogger {
void unableToRollbackConnection(Exception ignore); void unableToRollbackConnection(Exception ignore);
@LogMessage(level = INFO) @LogMessage(level = INFO)
@Message(value = "Unable to rollback isolated transaction on error [%s] : [%s]", id = 364) @Message(value = "Unable to rollback isolated transaction on error [%s]: [%s]", id = 364)
void unableToRollbackIsolatedTransaction( void unableToRollbackIsolatedTransaction(
Exception e, Exception e,
Exception ignore); Exception ignore);
@ -1273,7 +1273,7 @@ public interface CoreMessageLogger extends BasicLogger {
void unableToWrapResultSet(@Cause SQLException e); void unableToWrapResultSet(@Cause SQLException e);
@LogMessage(level = WARN) @LogMessage(level = WARN)
@Message(value = "I/O reported error writing cached file : %s: %s", id = 378) @Message(value = "I/O reported error writing cached file: %s: %s", id = 378)
void unableToWriteCachedFile( void unableToWriteCachedFile(
String path, String path,
String message); String message);
@ -1395,7 +1395,7 @@ public interface CoreMessageLogger extends BasicLogger {
void version(String versionString); void version(String versionString);
@LogMessage(level = WARN) @LogMessage(level = WARN)
@Message(value = "Warnings creating temp table : %s", id = 413) @Message(value = "Warnings creating temp table: %s", id = 413)
void warningsCreatingTempTable(SQLWarning warning); void warningsCreatingTempTable(SQLWarning warning);
@LogMessage(level = INFO) @LogMessage(level = INFO)
@ -1462,7 +1462,7 @@ public interface CoreMessageLogger extends BasicLogger {
* @see LobCreationLogging#contextualNClobCreationFailed * @see LobCreationLogging#contextualNClobCreationFailed
*/ */
@LogMessage(level = DEBUG) @LogMessage(level = DEBUG)
@Message(value = "Disabling contextual LOB creation as createClob() method threw error : %s", id = 424) @Message(value = "Disabling contextual LOB creation as createClob() method threw error: %s", id = 424)
@Deprecated @Deprecated
void disablingContextualLOBCreationSinceCreateClobFailed(Throwable t); void disablingContextualLOBCreationSinceCreateClobFailed(Throwable t);
@ -1489,7 +1489,7 @@ public interface CoreMessageLogger extends BasicLogger {
String jtaPlatform); String jtaPlatform);
@LogMessage(level = WARN) @LogMessage(level = WARN)
@Message(value = "Setting entity-identifier value binding where one already existed : %s.", id = 429) @Message(value = "Setting entity-identifier value binding where one already existed: %s.", id = 429)
void entityIdentifierValueBindingExists(String name); void entityIdentifierValueBindingExists(String name);
@LogMessage(level = WARN) @LogMessage(level = WARN)
@ -1585,7 +1585,7 @@ public interface CoreMessageLogger extends BasicLogger {
void explicitSkipLockedLockCombo(); void explicitSkipLockedLockCombo();
@LogMessage(level = INFO) @LogMessage(level = INFO)
@Message(value = "'jakarta.persistence.validation.mode' named multiple values : %s", id = 448) @Message(value = "'jakarta.persistence.validation.mode' named multiple values: %s", id = 448)
void multipleValidationModes(String modes); void multipleValidationModes(String modes);
@LogMessage(level = WARN) @LogMessage(level = WARN)
@ -1616,7 +1616,7 @@ public interface CoreMessageLogger extends BasicLogger {
void unableToLoadScannedClassOrResource(@Cause Exception e); void unableToLoadScannedClassOrResource(@Cause Exception e);
@LogMessage(level = WARN) @LogMessage(level = WARN)
@Message(value = "Exception while discovering OSGi service implementations : %s", id = 453) @Message(value = "Exception while discovering OSGi service implementations: %s", id = 453)
void unableToDiscoverOsgiService(String service, @Cause Exception e); void unableToDiscoverOsgiService(String service, @Cause Exception e);
@LogMessage(level = WARN) @LogMessage(level = WARN)
@ -1640,7 +1640,7 @@ public interface CoreMessageLogger extends BasicLogger {
void creatingPooledLoOptimizer(int incrementSize, String name); void creatingPooledLoOptimizer(int incrementSize, String name);
@LogMessage(level = WARN) @LogMessage(level = WARN)
@Message(value = "Unable to interpret type [%s] as an AttributeConverter due to an exception : %s", id = 468) @Message(value = "Unable to interpret type [%s] as an AttributeConverter due to an exception: %s", id = 468)
void logBadHbmAttributeConverterType(String type, String exceptionMessage); void logBadHbmAttributeConverterType(String type, String exceptionMessage);
@Message(value = "The ClassLoaderService can not be reused. This instance was stopped already.", id = 469) @Message(value = "The ClassLoaderService can not be reused. This instance was stopped already.", id = 469)
@ -1664,7 +1664,7 @@ public interface CoreMessageLogger extends BasicLogger {
void cachedFileObsolete(File cachedFile); void cachedFileObsolete(File cachedFile);
@Message( @Message(
value = "Ambiguous persistent property methods detected on %s; mark one as @Transient : [%s] and [%s]", value = "Ambiguous persistent property methods detected on %s; mark one as @Transient: [%s] and [%s]",
id = 474 id = 474
) )
String ambiguousPropertyMethods(String entityName, String oneMethodSig, String secondMethodSig); String ambiguousPropertyMethods(String entityName, String oneMethodSig, String secondMethodSig);
@ -1674,7 +1674,7 @@ public interface CoreMessageLogger extends BasicLogger {
void logCannotLocateIndexColumnInformation(String columnIdentifierText, String indexIdentifierText); void logCannotLocateIndexColumnInformation(String columnIdentifierText, String indexIdentifierText);
@LogMessage(level = INFO) @LogMessage(level = INFO)
@Message(value = "Executing script '%s'", id = 476) @Message(value = "Executing script [%s]", id = 476)
void executingScript(String scriptName); void executingScript(String scriptName);
@LogMessage(level = INFO) @LogMessage(level = INFO)
@ -1749,7 +1749,11 @@ public interface CoreMessageLogger extends BasicLogger {
String bytecodeEnhancementFailedUnableToGetPrivateLookupFor(String className); String bytecodeEnhancementFailedUnableToGetPrivateLookupFor(String className);
@LogMessage(level = INFO) @LogMessage(level = INFO)
@Message(value = "Using JtaPlatform implementation: [%s]", id = 490) @Message(value = "No JTA platform available (set 'hibernate.transaction.jta.platform' to enable JTA platform integration)", id = 489)
void noJtaPlatform();
@LogMessage(level = INFO)
@Message(value = "Using JTA platform [%s]", id = 490)
void usingJtaPlatform(String jtaPlatformClassName); void usingJtaPlatform(String jtaPlatformClassName);
@LogMessage(level = WARN) @LogMessage(level = WARN)

View File

@ -66,7 +66,9 @@ public class GenerationTargetToDatabase implements GenerationTarget {
@Override @Override
public void beforeScript(ScriptSourceInput scriptSource) { public void beforeScript(ScriptSourceInput scriptSource) {
log.executingScript( scriptSource.getScriptDescription() ); if ( scriptSource.exists() ) {
log.executingScript( scriptSource.getScriptDescription() );
}
} }
@Override @Override

View File

@ -45,14 +45,16 @@ public class ScriptSourceInputAggregate implements ScriptSourceInput {
int size = 0; int size = 0;
for ( int i = 0; i < inputs.length; i++ ) { for ( int i = 0; i < inputs.length; i++ ) {
final AbstractScriptSourceInput scriptSourceInput = inputs[i]; final AbstractScriptSourceInput scriptSourceInput = inputs[i];
final Reader reader = scriptSourceInput.prepareReader(); if ( scriptSourceInput.exists() ) {
try { final Reader reader = scriptSourceInput.prepareReader();
log.executingScript( scriptSourceInput.getScriptDescription() ); try {
lists[i] = extractor.apply( reader ); log.executingScript( scriptSourceInput.getScriptDescription() );
size += lists[i].size(); lists[i] = extractor.apply( reader );
} size += lists[i].size();
finally { }
scriptSourceInput.releaseReader( reader ); finally {
scriptSourceInput.releaseReader( reader );
}
} }
} }
final List<String> list = new ArrayList<>( size ); final List<String> list = new ArrayList<>( size );

View File

@ -49,4 +49,9 @@ public class ScriptSourceInputNonExistentImpl extends AbstractScriptSourceInput
public List<String> extract(Function<Reader, List<String>> extractor) { public List<String> extract(Function<Reader, List<String>> extractor) {
return Collections.emptyList(); return Collections.emptyList();
} }
@Override
public boolean exists() {
return false;
}
} }

View File

@ -32,4 +32,8 @@ public interface ScriptSourceInput {
return false; return false;
} }
default boolean exists() {
return true;
}
} }

View File

@ -25,7 +25,7 @@ import org.junit.Test;
import org.jboss.logging.Logger; import org.jboss.logging.Logger;
import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertTrue;
/** /**
* @author Vlad Mihalcea * @author Vlad Mihalcea
@ -47,10 +47,7 @@ public class JtaPlatformLoggingTest extends BaseNonConfigCoreFunctionalTestCase
@Test @Test
public void test() { public void test() {
assertEquals( assertTrue( triggerable.triggerMessage().startsWith("HHH000490: Using JTA platform"));
"HHH000490: Using JtaPlatform implementation: [org.hibernate.testing.jta.TestingJtaPlatformImpl]",
triggerable.triggerMessage()
);
} }
@Override @Override