From c81d7e5d8ca0ff0a267b8e6eda8e3beb92efe629 Mon Sep 17 00:00:00 2001 From: seungtaekhong Date: Sat, 7 Sep 2024 11:22:07 +0900 Subject: [PATCH] update log content on loggingFilter --- .../global/security/LoggingFilter.java | 27 ++++++++++++------- 1 file changed, 18 insertions(+), 9 deletions(-) diff --git a/src/main/java/com/playkuround/playkuroundserver/global/security/LoggingFilter.java b/src/main/java/com/playkuround/playkuroundserver/global/security/LoggingFilter.java index 9722ec4..87850d2 100644 --- a/src/main/java/com/playkuround/playkuroundserver/global/security/LoggingFilter.java +++ b/src/main/java/com/playkuround/playkuroundserver/global/security/LoggingFilter.java @@ -13,28 +13,37 @@ @Slf4j public class LoggingFilter extends OncePerRequestFilter { - private static void logRequest(HttpServletRequest request) { - if (request.getRequestURI() != null && - (request.getRequestURI().contains("/prometheus") || request.getRequestURI().equals("/api/system-available"))) { + @Override + protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response, FilterChain filterChain) throws ServletException, IOException { + if (!isAsyncDispatch(request)) { + logRequest(request); + } + filterChain.doFilter(request, response); + } + + private void logRequest(HttpServletRequest request) { + if (isNotLogFilterTarget(request)) { return; } + String queryString = request.getQueryString(); String bearerToken = request.getHeader(HttpHeaders.AUTHORIZATION); log.info("Request : {} uri=[{}] content-type=[{}] token=[{}]", request.getMethod(), - queryString == null ? request.getRequestURI() : request.getRequestURI() + queryString, + queryString == null ? request.getRequestURI() : request.getRequestURI() + "?" + queryString, request.getContentType(), bearerToken); } - @Override - protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response, FilterChain filterChain) throws ServletException, IOException { - if (!isAsyncDispatch(request)) { - logRequest(request); + private boolean isNotLogFilterTarget(HttpServletRequest request) { + if (request.getRequestURI() == null) { + return false; } - filterChain.doFilter(request, response); + String requestURI = request.getRequestURI(); + return requestURI.contains("/prometheus") || requestURI.equals("/api/system-available"); } + }