Adjust logging of resource locations

This commit is contained in:
Rossen Stoyanchev 2021-10-14 17:18:34 +01:00
parent 0853baaa3f
commit 76c9306dda
2 changed files with 25 additions and 29 deletions

View File

@ -304,11 +304,6 @@ public class ResourceWebHandler implements WebHandler, InitializingBean {
public void afterPropertiesSet() throws Exception {
resolveResourceLocations();
if (logger.isWarnEnabled() && CollectionUtils.isEmpty(getLocations())) {
logger.warn("Locations list is empty. No resources will be served unless a " +
"custom ResourceResolver is configured as an alternative to PathResourceResolver.");
}
if (this.resourceResolvers.isEmpty()) {
this.resourceResolvers.add(new PathResourceResolver());
}
@ -341,6 +336,12 @@ public class ResourceWebHandler implements WebHandler, InitializingBean {
this.locationsToUse.clear();
this.locationsToUse.addAll(result);
if (logger.isInfoEnabled()) {
logger.info(!this.locationsToUse.isEmpty() ?
"Locations in use: " + locationToString(this.locationsToUse) :
"0 locations in use.");
}
}
/**
@ -350,10 +351,6 @@ public class ResourceWebHandler implements WebHandler, InitializingBean {
*/
protected void initAllowedLocations() {
if (CollectionUtils.isEmpty(getLocations())) {
if (logger.isInfoEnabled()) {
logger.info("Locations list is empty. No resources will be served unless a " +
"custom ResourceResolver is configured as an alternative to PathResourceResolver.");
}
return;
}
for (int i = getResourceResolvers().size() - 1; i >= 0; i--) {
@ -621,18 +618,13 @@ public class ResourceWebHandler implements WebHandler, InitializingBean {
@Override
public String toString() {
return "ResourceWebHandler " + formatLocations();
return "ResourceWebHandler " + locationToString(getLocations());
}
private Object formatLocations() {
if (!this.locationValues.isEmpty()) {
return this.locationValues.stream().collect(Collectors.joining("\", \"", "[\"", "\"]"));
}
if (!getLocations().isEmpty()) {
return "[" + getLocations().toString()
.replaceAll("class path resource", "Classpath")
.replaceAll("ServletContext resource", "ServletContext") + "]";
}
return Collections.emptyList();
private String locationToString(List<Resource> locations) {
return locations.toString()
.replaceAll("class path resource", "classpath")
.replaceAll("ServletContext resource", "ServletContext");
}
}

View File

@ -392,11 +392,6 @@ public class ResourceHttpRequestHandler extends WebContentGenerator
public void afterPropertiesSet() throws Exception {
resolveResourceLocations();
if (logger.isWarnEnabled() && CollectionUtils.isEmpty(getLocations())) {
logger.warn("Locations list is empty. No resources will be served unless a " +
"custom ResourceResolver is configured as an alternative to PathResourceResolver.");
}
if (this.resourceResolvers.isEmpty()) {
this.resourceResolvers.add(new PathResourceResolver());
}
@ -472,6 +467,12 @@ public class ResourceHttpRequestHandler extends WebContentGenerator
this.locationsToUse.clear();
this.locationsToUse.addAll(result);
if (logger.isInfoEnabled()) {
logger.info(!this.locationsToUse.isEmpty() ?
"Locations in use: " + locationToString(this.locationsToUse) :
"0 locations in use.");
}
}
/**
@ -810,10 +811,13 @@ public class ResourceHttpRequestHandler extends WebContentGenerator
@Override
public String toString() {
return "ResourceHttpRequestHandler " +
getLocations().toString()
.replaceAll("class path resource", "Classpath")
.replaceAll("ServletContext resource", "ServletContext");
return "ResourceHttpRequestHandler " + locationToString(getLocations());
}
private String locationToString(List<Resource> locations) {
return locations.toString()
.replaceAll("class path resource", "classpath")
.replaceAll("ServletContext resource", "ServletContext");
}
}