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 );
}
LOG.usingJtaPlatform( platform != null ? platform.getClass().getName() : "null" );
if ( platform != null && !(platform instanceof NoJtaPlatform) ) {
LOG.usingJtaPlatform( platform.getClass().getName() );
}
else {
LOG.noJtaPlatform();
}
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)
void batchContainedStatementsOnRelease();
@LogMessage(level = INFO)
@LogMessage(level = DEBUG)
@Message(value = "Bytecode provider: %s", id = 21)
void bytecodeProvider(String provider);
@ -91,7 +91,7 @@ public interface CoreMessageLogger extends BasicLogger {
void c3p0ProviderClassNotFound(String c3p0ProviderClassName);
@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);
@LogMessage(level = INFO)
@ -187,7 +187,7 @@ public interface CoreMessageLogger extends BasicLogger {
// void deprecatedForceDescriminatorAnnotation();
@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);
@LogMessage(level = INFO)
@ -264,7 +264,7 @@ public interface CoreMessageLogger extends BasicLogger {
void exceptionInBeforeTransactionCompletionInterceptor(@Cause Throwable e);
@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);
@LogMessage(level = ERROR)
@ -563,7 +563,7 @@ public interface CoreMessageLogger extends BasicLogger {
// void parameterPositionOccurredAsBothJpaAndHibernatePositionalParameter(Integer position);
@LogMessage(level = ERROR)
@Message(value = "Error parsing XML (%s) : %s", id = 196)
@Message(value = "Error parsing XML: (%s) %s", id = 196)
void parsingXmlError(
int lineNumber,
String message);
@ -576,7 +576,7 @@ public interface CoreMessageLogger extends BasicLogger {
String message);
@LogMessage(level = ERROR)
@Message(value = "Warning parsing XML (%s) : %s", id = 198)
@Message(value = "Warning parsing XML: (%s) %s", id = 198)
void parsingXmlWarning(
int lineNumber,
String message);
@ -615,11 +615,11 @@ public interface CoreMessageLogger extends BasicLogger {
void propertiesLoaded(Properties maskOut);
@LogMessage(level = DEBUG)
@Message(value = "hibernate.properties not found", id = 206)
@Message(value = "'hibernate.properties' not found", id = 206)
void propertiesNotFound();
@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);
// @LogMessage(level = WARN)
@ -793,7 +793,7 @@ public interface CoreMessageLogger extends BasicLogger {
void stoppingService();
@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);
@LogMessage(level = INFO)
@ -805,7 +805,7 @@ public interface CoreMessageLogger extends BasicLogger {
void synchronizationAlreadyRegistered(Synchronization synchronization);
@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(
Synchronization synchronization,
Throwable t);
@ -839,7 +839,7 @@ public interface CoreMessageLogger extends BasicLogger {
void typeDefinedNoRegistrationKeys(Object type);
@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(
String key,
Type old);
@ -855,7 +855,7 @@ public interface CoreMessageLogger extends BasicLogger {
@Cause NamingException e);
@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);
@LogMessage(level = WARN)
@ -966,7 +966,7 @@ public interface CoreMessageLogger extends BasicLogger {
void unableToCompleteSchemaValidation(@Cause SQLException e);
@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);
@LogMessage(level = ERROR)
@ -976,7 +976,7 @@ public interface CoreMessageLogger extends BasicLogger {
@Cause Throwable e);
@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);
@LogMessage(level = WARN)
@ -994,7 +994,7 @@ public interface CoreMessageLogger extends BasicLogger {
void unableToCreateSchema(@Cause Exception e);
@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(
String path,
SerializationException error);
@ -1034,7 +1034,7 @@ public interface CoreMessageLogger extends BasicLogger {
void unableToExecuteBatch(Exception e, String sql );
@LogMessage(level = WARN)
@Message(value = "Error executing resolver [%s] : %s", id = 316)
@Message(value = "Error executing resolver [%s]: %s", id = 316)
void unableToExecuteResolver(
DialectResolver abstractDialectResolver,
String message);
@ -1062,7 +1062,7 @@ public interface CoreMessageLogger extends BasicLogger {
void unableToInstantiateOptimizer(String type);
@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);
@LogMessage(level = WARN)
@ -1074,7 +1074,7 @@ public interface CoreMessageLogger extends BasicLogger {
void unableToLoadCommand(@Cause HibernateException e);
@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);
@LogMessage(level = ERROR)
@ -1095,11 +1095,11 @@ public interface CoreMessageLogger extends BasicLogger {
void unableToLocateMBeanServer();
@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);
@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);
@LogMessage(level = WARN)
@ -1166,7 +1166,7 @@ public interface CoreMessageLogger extends BasicLogger {
void unableToReleaseBatchStatement();
@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);
@LogMessage(level = INFO)
@ -1174,7 +1174,7 @@ public interface CoreMessageLogger extends BasicLogger {
void unableToReleaseContext(String message);
@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);
@LogMessage(level = INFO)
@ -1204,7 +1204,7 @@ public interface CoreMessageLogger extends BasicLogger {
String message);
@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);
@LogMessage(level = INFO)
@ -1212,7 +1212,7 @@ public interface CoreMessageLogger extends BasicLogger {
void unableToRollbackConnection(Exception ignore);
@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(
Exception e,
Exception ignore);
@ -1273,7 +1273,7 @@ public interface CoreMessageLogger extends BasicLogger {
void unableToWrapResultSet(@Cause SQLException e);
@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(
String path,
String message);
@ -1395,7 +1395,7 @@ public interface CoreMessageLogger extends BasicLogger {
void version(String versionString);
@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);
@LogMessage(level = INFO)
@ -1462,7 +1462,7 @@ public interface CoreMessageLogger extends BasicLogger {
* @see LobCreationLogging#contextualNClobCreationFailed
*/
@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
void disablingContextualLOBCreationSinceCreateClobFailed(Throwable t);
@ -1489,7 +1489,7 @@ public interface CoreMessageLogger extends BasicLogger {
String jtaPlatform);
@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);
@LogMessage(level = WARN)
@ -1585,7 +1585,7 @@ public interface CoreMessageLogger extends BasicLogger {
void explicitSkipLockedLockCombo();
@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);
@LogMessage(level = WARN)
@ -1616,7 +1616,7 @@ public interface CoreMessageLogger extends BasicLogger {
void unableToLoadScannedClassOrResource(@Cause Exception e);
@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);
@LogMessage(level = WARN)
@ -1640,7 +1640,7 @@ public interface CoreMessageLogger extends BasicLogger {
void creatingPooledLoOptimizer(int incrementSize, String name);
@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);
@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);
@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
)
String ambiguousPropertyMethods(String entityName, String oneMethodSig, String secondMethodSig);
@ -1674,7 +1674,7 @@ public interface CoreMessageLogger extends BasicLogger {
void logCannotLocateIndexColumnInformation(String columnIdentifierText, String indexIdentifierText);
@LogMessage(level = INFO)
@Message(value = "Executing script '%s'", id = 476)
@Message(value = "Executing script [%s]", id = 476)
void executingScript(String scriptName);
@LogMessage(level = INFO)
@ -1749,7 +1749,11 @@ public interface CoreMessageLogger extends BasicLogger {
String bytecodeEnhancementFailedUnableToGetPrivateLookupFor(String className);
@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);
@LogMessage(level = WARN)

View File

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

View File

@ -45,14 +45,16 @@ public class ScriptSourceInputAggregate implements ScriptSourceInput {
int size = 0;
for ( int i = 0; i < inputs.length; i++ ) {
final AbstractScriptSourceInput scriptSourceInput = inputs[i];
final Reader reader = scriptSourceInput.prepareReader();
try {
log.executingScript( scriptSourceInput.getScriptDescription() );
lists[i] = extractor.apply( reader );
size += lists[i].size();
}
finally {
scriptSourceInput.releaseReader( reader );
if ( scriptSourceInput.exists() ) {
final Reader reader = scriptSourceInput.prepareReader();
try {
log.executingScript( scriptSourceInput.getScriptDescription() );
lists[i] = extractor.apply( reader );
size += lists[i].size();
}
finally {
scriptSourceInput.releaseReader( reader );
}
}
}
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) {
return Collections.emptyList();
}
@Override
public boolean exists() {
return false;
}
}

View File

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

View File

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