diff --git a/spring-webmvc/src/main/java/org/springframework/web/servlet/DispatcherServlet.java b/spring-webmvc/src/main/java/org/springframework/web/servlet/DispatcherServlet.java index 3151ed583b32..109fd4ca5a41 100644 --- a/spring-webmvc/src/main/java/org/springframework/web/servlet/DispatcherServlet.java +++ b/spring-webmvc/src/main/java/org/springframework/web/servlet/DispatcherServlet.java @@ -1018,11 +1018,14 @@ else if (isEnableLoggingRequestDetails()) { if (traceOn) { List values = Collections.list(request.getHeaderNames()); - String headers = values.isEmpty() ? "" : "masked"; + String headers; if (isEnableLoggingRequestDetails()) { headers = values.stream().map(name -> name + ":" + Collections.list(request.getHeaders(name))) .collect(Collectors.joining(", ")); } + else { + headers = (!values.isEmpty() ? "masked" : ""); + } return message + ", headers={" + headers + "} in DispatcherServlet '" + getServletName() + "'"; } else {