Skip to content

Commit

Permalink
merge: 로깅 로직 수정
Browse files Browse the repository at this point in the history
Fix/#94 스포티파이 유사곡 검색 오류
  • Loading branch information
hong-sile authored Aug 18, 2024
2 parents f8afb52 + 324cdb2 commit 48361fb
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
3 changes: 2 additions & 1 deletion src/main/java/play/pluv/config/FilterConfiguration.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import org.springframework.boot.web.servlet.FilterRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.Ordered;

@Configuration
public class FilterConfiguration {
Expand All @@ -15,7 +16,7 @@ public FilterRegistrationBean<LogFilter> myFilterRegistration() {
registration.addUrlPatterns(
"/music/*", "/oauth/*", "/login/*", "/playlist/*"
);
registration.setOrder(1); // 필터 순서 지정 (optional)
registration.setOrder(Ordered.HIGHEST_PRECEDENCE); // 필터 순서 지정 (optional)
return registration;
}
}
11 changes: 8 additions & 3 deletions src/main/java/play/pluv/config/LogFilter.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.UnsupportedEncodingException;
import lombok.extern.slf4j.Slf4j;
import org.slf4j.MDC;
import org.springframework.web.util.ContentCachingRequestWrapper;
Expand All @@ -25,16 +26,20 @@ public void doFilter(
final ContentCachingResponseWrapper httpServletResponse
= new ContentCachingResponseWrapper((HttpServletResponse) response);

loggingRequest(httpServletRequest);
filterChain.doFilter(httpServletRequest, httpServletResponse);
loggingRequest(httpServletRequest);
loggingResponse(httpServletResponse);
}

private static void loggingRequest(final ContentCachingRequestWrapper httpServletRequest) {
private static void loggingRequest(final ContentCachingRequestWrapper httpServletRequest)
throws UnsupportedEncodingException {
final String uri = httpServletRequest.getRequestURI();

//request 내용 확인
final String reqContent = new String(httpServletRequest.getContentAsByteArray());
final String reqContent = new String(
httpServletRequest.getContentAsByteArray(),
httpServletRequest.getCharacterEncoding()
);
MDC.put("uri", uri);
MDC.put("contentBody", reqContent);
log.info("request logging");
Expand Down

0 comments on commit 48361fb

Please sign in to comment.