Suppress handler mapping logging for introspector

Closes gh-30349
This commit is contained in:
rstoyanchev 2023-09-20 18:03:25 +01:00
parent 2530efd1c7
commit 0f7c406a86
2 changed files with 11 additions and 5 deletions

View File

@ -78,6 +78,9 @@ import org.springframework.web.util.pattern.PathPatternParser;
public abstract class AbstractHandlerMapping extends WebApplicationObjectSupport
implements HandlerMapping, Ordered, BeanNameAware {
final static String SUPPRESS_LOGGING_ATTRIBUTE = AbstractHandlerMapping.class.getName() + ".SUPPRESS_LOGGING";
/** Dedicated "hidden" logger for request mappings. */
protected final Log mappingsLogger =
LogDelegateFactory.getHiddenLog(HandlerMapping.class.getName() + ".Mappings");
@ -520,11 +523,13 @@ public abstract class AbstractHandlerMapping extends WebApplicationObjectSupport
HandlerExecutionChain executionChain = getHandlerExecutionChain(handler, request);
if (logger.isTraceEnabled()) {
logger.trace("Mapped to " + handler);
}
else if (logger.isDebugEnabled() && !DispatcherType.ASYNC.equals(request.getDispatcherType())) {
logger.debug("Mapped to " + executionChain.getHandler());
if (request.getAttribute(SUPPRESS_LOGGING_ATTRIBUTE) == null) {
if (logger.isTraceEnabled()) {
logger.trace("Mapped to " + handler);
}
else if (logger.isDebugEnabled() && !DispatcherType.ASYNC.equals(request.getDispatcherType())) {
logger.debug("Mapped to " + executionChain.getHandler());
}
}
if (hasCorsConfigurationSource(handler) || CorsUtils.isPreFlightRequest(request)) {

View File

@ -261,6 +261,7 @@ public class HandlerMappingIntrospector
AttributesPreservingRequest(HttpServletRequest request) {
super(request);
this.attributes = initAttributes(request);
this.attributes.put(AbstractHandlerMapping.SUPPRESS_LOGGING_ATTRIBUTE, Boolean.TRUE);
}
private Map<String, Object> initAttributes(HttpServletRequest request) {