Merge pull request #13512 from izeye:config-file-application-listener-log-level-guard

* pr/13512:
  Add log level guards in ConfigFileApplicationListener
pull/13946/head
Stephane Nicoll 7 years ago
commit deea8ebc0d

@ -386,8 +386,10 @@ public class ConfigFileApplicationListener
return;
}
if (this.activatedProfiles) {
this.logger.debug("Profiles already activated, '" + profiles
+ "' will not be applied");
if (this.logger.isDebugEnabled()) {
this.logger.debug("Profiles already activated, '" + profiles
+ "' will not be applied");
}
return;
}
this.profiles.addAll(profiles);
@ -501,23 +503,28 @@ public class ConfigFileApplicationListener
DocumentFilter filter, DocumentConsumer consumer) {
try {
Resource resource = this.resourceLoader.getResource(location);
String description = getDescription(location, resource);
if (profile != null) {
description = description + " for profile " + profile;
}
if (resource == null || !resource.exists()) {
this.logger.trace("Skipped missing config " + description);
if (this.logger.isTraceEnabled()) {
this.logger.trace("Skipped missing config "
+ getDescription(location, resource, profile));
}
return;
}
if (!StringUtils.hasText(
StringUtils.getFilenameExtension(resource.getFilename()))) {
this.logger.trace("Skipped empty config extension " + description);
if (this.logger.isTraceEnabled()) {
this.logger.trace("Skipped empty config extension "
+ getDescription(location, resource, profile));
}
return;
}
String name = "applicationConfig: [" + location + "]";
List<Document> documents = loadDocuments(loader, name, resource);
if (CollectionUtils.isEmpty(documents)) {
this.logger.trace("Skipped unloaded config " + description);
if (this.logger.isTraceEnabled()) {
this.logger.trace("Skipped unloaded config "
+ getDescription(location, resource, profile));
}
return;
}
List<Document> loaded = new ArrayList<>();
@ -531,7 +538,10 @@ public class ConfigFileApplicationListener
Collections.reverse(loaded);
if (!loaded.isEmpty()) {
loaded.forEach((document) -> consumer.accept(profile, document));
this.logger.debug("Loaded config file " + description);
if (this.logger.isDebugEnabled()) {
this.logger.debug("Loaded config file "
+ getDescription(location, resource, profile));
}
}
}
catch (Exception ex) {
@ -576,6 +586,13 @@ public class ConfigFileApplicationListener
}).collect(Collectors.toList());
}
private String getDescription(String location, Resource resource,
Profile profile) {
String description = getDescription(location, resource);
return (profile != null ? description + " for profile " + profile
: description);
}
private String getDescription(String location, Resource resource) {
try {
if (resource != null) {

Loading…
Cancel
Save