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"); } + }