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 JtaPlatform initiateService(Map<String, Object> configurationValues, Serv
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)
@ -563,7 +563,7 @@ void noSessionFactoryWithJndiName(
// 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 @@ void parsingXmlErrorForFile(
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 @@ void parsingXmlWarningForFile(
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)
@ -994,7 +994,7 @@ void unableToCreateProxyFactory(
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);
@ -1674,7 +1674,7 @@ void cannotResolveNonNullableTransientDependencies(
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 @@ void attemptToAssociateProxyWithTwoOpenSessions(
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,8 +66,10 @@ public void prepare() {
@Override @Override
public void beforeScript(ScriptSourceInput scriptSource) { public void beforeScript(ScriptSourceInput scriptSource) {
if ( scriptSource.exists() ) {
log.executingScript( scriptSource.getScriptDescription() ); log.executingScript( scriptSource.getScriptDescription() );
} }
}
@Override @Override
public void accept(String command) { public void accept(String command) {

View File

@ -45,6 +45,7 @@ public List<String> extract(Function<Reader, List<String>> extractor) {
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];
if ( scriptSourceInput.exists() ) {
final Reader reader = scriptSourceInput.prepareReader(); final Reader reader = scriptSourceInput.prepareReader();
try { try {
log.executingScript( scriptSourceInput.getScriptDescription() ); log.executingScript( scriptSourceInput.getScriptDescription() );
@ -55,6 +56,7 @@ public List<String> extract(Function<Reader, List<String>> extractor) {
scriptSourceInput.releaseReader( reader ); scriptSourceInput.releaseReader( reader );
} }
} }
}
final List<String> list = new ArrayList<>( size ); final List<String> list = new ArrayList<>( size );
for ( List<String> strings : lists ) { for ( List<String> strings : lists ) {
list.addAll( strings ); list.addAll( strings );

View File

@ -49,4 +49,9 @@ public boolean containsScript(URL url) {
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 @@ default boolean containsScript(URL url) {
return false; return false;
} }
default boolean exists() {
return true;
}
} }

View File

@ -25,7 +25,7 @@
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 @@ protected void addSettings(Map<String,Object> settings) {
@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