Guard potentially expensive log message computations.
Original Pull Request #3883
This commit is contained in:
@@ -88,14 +88,18 @@ public class ServerAddressPropertyEditor extends PropertyEditorSupport {
|
||||
private ServerAddress parseServerAddress(String source) {
|
||||
|
||||
if (!StringUtils.hasText(source)) {
|
||||
LOG.warn(String.format(COULD_NOT_PARSE_ADDRESS_MESSAGE, "source", source));
|
||||
if(LOG.isWarnEnabled()) {
|
||||
LOG.warn(String.format(COULD_NOT_PARSE_ADDRESS_MESSAGE, "source", source));
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
String[] hostAndPort = extractHostAddressAndPort(source.trim());
|
||||
|
||||
if (hostAndPort.length > 2) {
|
||||
LOG.warn(String.format(COULD_NOT_PARSE_ADDRESS_MESSAGE, "source", source));
|
||||
if(LOG.isWarnEnabled()) {
|
||||
LOG.warn(String.format(COULD_NOT_PARSE_ADDRESS_MESSAGE, "source", source));
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -105,9 +109,13 @@ public class ServerAddressPropertyEditor extends PropertyEditorSupport {
|
||||
|
||||
return port == null ? new ServerAddress(hostAddress) : new ServerAddress(hostAddress, port);
|
||||
} catch (UnknownHostException e) {
|
||||
LOG.warn(String.format(COULD_NOT_PARSE_ADDRESS_MESSAGE, "host", hostAndPort[0]));
|
||||
if(LOG.isWarnEnabled()) {
|
||||
LOG.warn(String.format(COULD_NOT_PARSE_ADDRESS_MESSAGE, "host", hostAndPort[0]));
|
||||
}
|
||||
} catch (NumberFormatException e) {
|
||||
LOG.warn(String.format(COULD_NOT_PARSE_ADDRESS_MESSAGE, "port", hostAndPort[1]));
|
||||
if(LOG.isWarnEnabled()) {
|
||||
LOG.warn(String.format(COULD_NOT_PARSE_ADDRESS_MESSAGE, "port", hostAndPort[1]));
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
|
||||
@@ -208,8 +208,10 @@ public class MongoPersistentEntityIndexCreator implements ApplicationListener<Ma
|
||||
orElse(null);
|
||||
|
||||
} catch (Exception e) {
|
||||
LOGGER.debug(
|
||||
String.format("Failed to load index information for collection '%s'.", indexDefinition.getCollection()), e);
|
||||
if(LOGGER.isDebugEnabled()) {
|
||||
LOGGER.debug(
|
||||
String.format("Failed to load index information for collection '%s'.", indexDefinition.getCollection()), e);
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
|
||||
@@ -170,7 +170,9 @@ public class MongoPersistentEntityIndexResolver implements IndexResolver {
|
||||
indexes.addAll(indexDefinitions);
|
||||
}
|
||||
} catch (CyclicPropertyReferenceException e) {
|
||||
LOGGER.info(e.getMessage());
|
||||
if(LOGGER.isInfoEnabled()) {
|
||||
LOGGER.info(e.getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -175,9 +175,11 @@ public class ReactiveMongoPersistentEntityIndexCreator {
|
||||
.filter(indexInfo -> ObjectUtils.nullSafeEquals(indexNameToLookUp, indexInfo.getName())) //
|
||||
.next() //
|
||||
.doOnError(e -> {
|
||||
LOGGER.debug(
|
||||
String.format("Failed to load index information for collection '%s'.", indexDefinition.getCollection()),
|
||||
e);
|
||||
if(LOGGER.isDebugEnabled()) {
|
||||
LOGGER.debug(
|
||||
String.format("Failed to load index information for collection '%s'.", indexDefinition.getCollection()),
|
||||
e);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -93,9 +93,11 @@ public class BasicMongoPersistentProperty extends AnnotationBasedPersistentPrope
|
||||
|
||||
String annotatedName = getAnnotatedFieldName();
|
||||
if (!ID_FIELD_NAME.equals(annotatedName)) {
|
||||
LOG.warn(String.format(
|
||||
"Customizing field name for id property '%s.%s' is not allowed! Custom name ('%s') will not be considered!",
|
||||
owner.getName(), getName(), annotatedName));
|
||||
if(LOG.isWarnEnabled()) {
|
||||
LOG.warn(String.format(
|
||||
"Customizing field name for id property '%s.%s' is not allowed! Custom name ('%s') will not be considered!",
|
||||
owner.getName(), getName(), annotatedName));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -40,7 +40,9 @@ public class LoggingEventListener extends AbstractMongoEventListener<Object> {
|
||||
*/
|
||||
@Override
|
||||
public void onBeforeConvert(BeforeConvertEvent<Object> event) {
|
||||
LOGGER.info(String.format("onBeforeConvert: %s", event.getSource()));
|
||||
if(LOGGER.isInfoEnabled()) {
|
||||
LOGGER.info(String.format("onBeforeConvert: %s", event.getSource()));
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -49,7 +51,9 @@ public class LoggingEventListener extends AbstractMongoEventListener<Object> {
|
||||
*/
|
||||
@Override
|
||||
public void onBeforeSave(BeforeSaveEvent<Object> event) {
|
||||
LOGGER.info(String.format("onBeforeSave: %s, %s", event.getSource(), serializeToJsonSafely(event.getDocument())));
|
||||
if(LOGGER.isInfoEnabled()) {
|
||||
LOGGER.info(String.format("onBeforeSave: %s, %s", event.getSource(), serializeToJsonSafely(event.getDocument())));
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -58,7 +62,9 @@ public class LoggingEventListener extends AbstractMongoEventListener<Object> {
|
||||
*/
|
||||
@Override
|
||||
public void onAfterSave(AfterSaveEvent<Object> event) {
|
||||
LOGGER.info(String.format("onAfterSave: %s, %s", event.getSource(), serializeToJsonSafely(event.getDocument())));
|
||||
if(LOGGER.isInfoEnabled()) {
|
||||
LOGGER.info(String.format("onAfterSave: %s, %s", event.getSource(), serializeToJsonSafely(event.getDocument())));
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -67,7 +73,9 @@ public class LoggingEventListener extends AbstractMongoEventListener<Object> {
|
||||
*/
|
||||
@Override
|
||||
public void onAfterLoad(AfterLoadEvent<Object> event) {
|
||||
LOGGER.info(String.format("onAfterLoad: %s", serializeToJsonSafely(event.getDocument())));
|
||||
if(LOGGER.isInfoEnabled()) {
|
||||
LOGGER.info(String.format("onAfterLoad: %s", serializeToJsonSafely(event.getDocument())));
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -76,7 +84,9 @@ public class LoggingEventListener extends AbstractMongoEventListener<Object> {
|
||||
*/
|
||||
@Override
|
||||
public void onAfterConvert(AfterConvertEvent<Object> event) {
|
||||
LOGGER.info(String.format("onAfterConvert: %s, %s", serializeToJsonSafely(event.getDocument()), event.getSource()));
|
||||
if(LOGGER.isInfoEnabled()) {
|
||||
LOGGER.info(String.format("onAfterConvert: %s, %s", serializeToJsonSafely(event.getDocument()), event.getSource()));
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -85,7 +95,9 @@ public class LoggingEventListener extends AbstractMongoEventListener<Object> {
|
||||
*/
|
||||
@Override
|
||||
public void onAfterDelete(AfterDeleteEvent<Object> event) {
|
||||
LOGGER.info(String.format("onAfterDelete: %s", serializeToJsonSafely(event.getDocument())));
|
||||
if(LOGGER.isInfoEnabled()) {
|
||||
LOGGER.info(String.format("onAfterDelete: %s", serializeToJsonSafely(event.getDocument())));
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -94,6 +106,8 @@ public class LoggingEventListener extends AbstractMongoEventListener<Object> {
|
||||
*/
|
||||
@Override
|
||||
public void onBeforeDelete(BeforeDeleteEvent<Object> event) {
|
||||
LOGGER.info(String.format("onBeforeDelete: %s", serializeToJsonSafely(event.getDocument())));
|
||||
if(LOGGER.isInfoEnabled()) {
|
||||
LOGGER.info(String.format("onBeforeDelete: %s", serializeToJsonSafely(event.getDocument())));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -59,14 +59,14 @@ public class ValidatingMongoEventListener extends AbstractMongoEventListener<Obj
|
||||
public void onBeforeSave(BeforeSaveEvent<Object> event) {
|
||||
|
||||
if (LOG.isDebugEnabled()) {
|
||||
LOG.debug(String.format("Validating object: {}", event.getSource()));
|
||||
LOG.debug(String.format("Validating object: %s", event.getSource()));
|
||||
}
|
||||
Set violations = validator.validate(event.getSource());
|
||||
|
||||
if (!violations.isEmpty()) {
|
||||
|
||||
if (LOG.isDebugEnabled()) {
|
||||
LOG.info(String.format("During object: {} validation violations found: {}", event.getSource(), violations));
|
||||
LOG.info(String.format("During object: %s validation violations found: %s", event.getSource(), violations));
|
||||
}
|
||||
throw new ConstraintViolationException(violations);
|
||||
}
|
||||
|
||||
@@ -136,7 +136,10 @@ class IndexEnsuringQueryCreationListener implements QueryCreationListener<PartTr
|
||||
}
|
||||
}
|
||||
}
|
||||
LOG.debug(String.format("Created %s!", index));
|
||||
|
||||
if (LOG.isDebugEnabled()) {
|
||||
LOG.debug(String.format("Created %s!", index));
|
||||
}
|
||||
}
|
||||
|
||||
public boolean isIndexOnUnwrappedType(Part part) {
|
||||
|
||||
@@ -289,7 +289,9 @@ public class CleanMongoDB implements TestRule {
|
||||
}
|
||||
|
||||
client.getDatabase(dbName).drop();
|
||||
LOGGER.debug(String.format("Dropping DB '%s'. ", dbName));
|
||||
if(LOGGER.isDebugEnabled()) {
|
||||
LOGGER.debug(String.format("Dropping DB '%s'. ", dbName));
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -306,11 +308,15 @@ public class CleanMongoDB implements TestRule {
|
||||
|
||||
if (types.contains(Struct.COLLECTION)) {
|
||||
collection.drop();
|
||||
LOGGER.debug(String.format("Dropping collection '%s' for DB '%s'. ", collectionName, db.getName()));
|
||||
if(LOGGER.isDebugEnabled()) {
|
||||
LOGGER.debug(String.format("Dropping collection '%s' for DB '%s'. ", collectionName, db.getName()));
|
||||
}
|
||||
} else if (types.contains(Struct.INDEX)) {
|
||||
collection.dropIndexes();
|
||||
LOGGER.debug(
|
||||
String.format("Dropping indexes in collection '%s' for DB '%s'. ", collectionName, db.getName()));
|
||||
if(LOGGER.isDebugEnabled()) {
|
||||
LOGGER.debug(
|
||||
String.format("Dropping indexes in collection '%s' for DB '%s'. ", collectionName, db.getName()));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user