From 0f7c406a8622fb6b4f9d1dfeed9d4f9eea7b071f Mon Sep 17 00:00:00 2001 From: rstoyanchev Date: Wed, 20 Sep 2023 18:03:25 +0100 Subject: [PATCH] Suppress handler mapping logging for introspector Closes gh-30349 --- .../servlet/handler/AbstractHandlerMapping.java | 15 ++++++++++----- .../handler/HandlerMappingIntrospector.java | 1 + 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/spring-webmvc/src/main/java/org/springframework/web/servlet/handler/AbstractHandlerMapping.java b/spring-webmvc/src/main/java/org/springframework/web/servlet/handler/AbstractHandlerMapping.java index ec695ea368d9..be5b00bec86a 100644 --- a/spring-webmvc/src/main/java/org/springframework/web/servlet/handler/AbstractHandlerMapping.java +++ b/spring-webmvc/src/main/java/org/springframework/web/servlet/handler/AbstractHandlerMapping.java @@ -78,6 +78,9 @@ 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 final HandlerExecutionChain getHandler(HttpServletRequest request) throws 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)) { diff --git a/spring-webmvc/src/main/java/org/springframework/web/servlet/handler/HandlerMappingIntrospector.java b/spring-webmvc/src/main/java/org/springframework/web/servlet/handler/HandlerMappingIntrospector.java index 6c194b88d834..7411efe5bfff 100644 --- a/spring-webmvc/src/main/java/org/springframework/web/servlet/handler/HandlerMappingIntrospector.java +++ b/spring-webmvc/src/main/java/org/springframework/web/servlet/handler/HandlerMappingIntrospector.java @@ -261,6 +261,7 @@ private static class AttributesPreservingRequest extends HttpServletRequestWrapp AttributesPreservingRequest(HttpServletRequest request) { super(request); this.attributes = initAttributes(request); + this.attributes.put(AbstractHandlerMapping.SUPPRESS_LOGGING_ATTRIBUTE, Boolean.TRUE); } private Map initAttributes(HttpServletRequest request) {