Skip to content

Commit

Permalink
update log content on loggingFilter
Browse files Browse the repository at this point in the history
  • Loading branch information
redcarrot1 committed Sep 7, 2024
1 parent 3cc40c7 commit c81d7e5
Showing 1 changed file with 18 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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");
}


}


0 comments on commit c81d7e5

Please sign in to comment.