Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat:client request time log add #172

Merged
merged 1 commit into from
Oct 27, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.List;
import lombok.NonNull;
import lombok.RequiredArgsConstructor;
Expand Down Expand Up @@ -47,6 +49,9 @@ public class JwtAuthenticationFilter extends OncePerRequestFilter {
private final MemberRepository memberRepository;
private static final String REFRESH_TOKEN_URI = "/api/v1/auth/refresh";

// 스레드 안전
// 매번 요청마다 객체 생성하는데 싱글톤으로 유지
private static final DateTimeFormatter DATE_TIME_FORMATTER = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");

@Override
protected void doFilterInternal(
Expand All @@ -58,8 +63,13 @@ protected void doFilterInternal(
String requestMethod = request.getMethod(); // 요청된 method (GET,POST,etc....)
String clientProxyIP = HeaderUtil.getClientProxyIP(request); // 요청 IP

LocalDateTime currentTime = LocalDateTime.now();
String formattedTime = currentTime.format(DATE_TIME_FORMATTER);

// 모든 요청에 대한 정보 로깅
log.info("Client request: method={}, URI={}, IP={}", requestMethod, requestURI,clientProxyIP);
log.info("Request Time={}", formattedTime);
log.info("Client method={}, URI={}", requestMethod, requestURI);
log.info("Client IP={}", clientProxyIP);

// 로그인 한 유저가 리프레시 토큰으로 요청할 때
if (requestURI.equals(REFRESH_TOKEN_URI)) {
Expand Down