From 53c50b3a05a187ea7dbf135bb99bf7c67a366277 Mon Sep 17 00:00:00 2001 From: Liam Date: Fri, 12 Apr 2024 20:07:25 +0100 Subject: [PATCH] don't log as much for request logging --- .../cc/fascinated/log/TransactionLogger.java | 30 +++---------------- 1 file changed, 4 insertions(+), 26 deletions(-) diff --git a/src/main/java/cc/fascinated/log/TransactionLogger.java b/src/main/java/cc/fascinated/log/TransactionLogger.java index ab9de46..75226e5 100644 --- a/src/main/java/cc/fascinated/log/TransactionLogger.java +++ b/src/main/java/cc/fascinated/log/TransactionLogger.java @@ -22,14 +22,13 @@ import java.util.Map; import java.util.Map.Entry; @ControllerAdvice -@Slf4j(topic = "Req/Res Transaction") +@Slf4j(topic = "Req Transaction") public class TransactionLogger implements ResponseBodyAdvice { @Override public Object beforeBodyWrite(Object body, @NonNull MethodParameter returnType, @NonNull MediaType selectedContentType, @NonNull Class> selectedConverterType, @NonNull ServerHttpRequest rawRequest, @NonNull ServerHttpResponse rawResponse) { HttpServletRequest request = ((ServletServerHttpRequest) rawRequest).getServletRequest(); - HttpServletResponse response = ((ServletServerHttpResponse) rawResponse).getServletResponse(); // Get the request ip ip String ip = IPUtils.getRealIp(request); @@ -40,33 +39,12 @@ public class TransactionLogger implements ResponseBodyAdvice { params.put(entry.getKey(), Arrays.toString(entry.getValue())); } - // Getting headers - Map headers = new HashMap<>(); - Enumeration headerNames = request.getHeaderNames(); - while (headerNames.hasMoreElements()) { - String headerName = headerNames.nextElement(); - headers.put(headerName, request.getHeader(headerName)); - } - - // Log the request - log.info(String.format("[Req] %s | %s | '%s', params=%s, headers=%s", + // Logging the request + log.info(String.format("[Req] %s | %s | '%s', params=%s", request.getMethod(), ip, request.getRequestURI(), - params, - headers - )); - - // Getting response headers - headers = new HashMap<>(); - for (String headerName : response.getHeaderNames()) { - headers.put(headerName, response.getHeader(headerName)); - } - - // Log the response - log.info(String.format("[Res] %s, headers=%s", - response.getStatus(), - headers + params )); return body; }