Skip to content

Commit 0f7c406

Browse files
committed
Suppress handler mapping logging for introspector
Closes gh-30349
1 parent 2530efd commit 0f7c406

File tree

2 files changed

+11
-5
lines changed

2 files changed

+11
-5
lines changed

spring-webmvc/src/main/java/org/springframework/web/servlet/handler/AbstractHandlerMapping.java

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,9 @@
7878
public abstract class AbstractHandlerMapping extends WebApplicationObjectSupport
7979
implements HandlerMapping, Ordered, BeanNameAware {
8080

81+
final static String SUPPRESS_LOGGING_ATTRIBUTE = AbstractHandlerMapping.class.getName() + ".SUPPRESS_LOGGING";
82+
83+
8184
/** Dedicated "hidden" logger for request mappings. */
8285
protected final Log mappingsLogger =
8386
LogDelegateFactory.getHiddenLog(HandlerMapping.class.getName() + ".Mappings");
@@ -520,11 +523,13 @@ public final HandlerExecutionChain getHandler(HttpServletRequest request) throws
520523

521524
HandlerExecutionChain executionChain = getHandlerExecutionChain(handler, request);
522525

523-
if (logger.isTraceEnabled()) {
524-
logger.trace("Mapped to " + handler);
525-
}
526-
else if (logger.isDebugEnabled() && !DispatcherType.ASYNC.equals(request.getDispatcherType())) {
527-
logger.debug("Mapped to " + executionChain.getHandler());
526+
if (request.getAttribute(SUPPRESS_LOGGING_ATTRIBUTE) == null) {
527+
if (logger.isTraceEnabled()) {
528+
logger.trace("Mapped to " + handler);
529+
}
530+
else if (logger.isDebugEnabled() && !DispatcherType.ASYNC.equals(request.getDispatcherType())) {
531+
logger.debug("Mapped to " + executionChain.getHandler());
532+
}
528533
}
529534

530535
if (hasCorsConfigurationSource(handler) || CorsUtils.isPreFlightRequest(request)) {

spring-webmvc/src/main/java/org/springframework/web/servlet/handler/HandlerMappingIntrospector.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -261,6 +261,7 @@ private static class AttributesPreservingRequest extends HttpServletRequestWrapp
261261
AttributesPreservingRequest(HttpServletRequest request) {
262262
super(request);
263263
this.attributes = initAttributes(request);
264+
this.attributes.put(AbstractHandlerMapping.SUPPRESS_LOGGING_ATTRIBUTE, Boolean.TRUE);
264265
}
265266

266267
private Map<String, Object> initAttributes(HttpServletRequest request) {

0 commit comments

Comments
 (0)