Skip to content

Commit eafbae4

Browse files
authored
Merge pull request #40 from babzip/feat/logging
Feat/logging
2 parents e6018fe + 688d895 commit eafbae4

4 files changed

Lines changed: 21 additions & 1 deletion

File tree

src/main/java/com/babzip/backend/global/exception/GlobalExceptionHandler.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import com.babzip.backend.global.response.ResponseBody;
44
import com.babzip.backend.global.response.ResponseUtil;
5+
import jakarta.servlet.http.HttpServletRequest;
56
import lombok.RequiredArgsConstructor;
67
import lombok.extern.slf4j.Slf4j;
78
import org.springframework.http.HttpStatus;
@@ -17,8 +18,10 @@
1718
public class GlobalExceptionHandler {
1819

1920
@ExceptionHandler(BusinessException.class)
20-
public ResponseEntity<ResponseBody<Void>> businessException(BusinessException e) {
21+
public ResponseEntity<ResponseBody<Void>> businessException(BusinessException e, HttpServletRequest request) {
2122
ExceptionType exceptionType = e.getExceptionType();
23+
log.error("🔥 [{} {}] 요청 중 예외 발생: {}", request.getMethod(), request.getRequestURI(), e.getMessage(), e);
24+
2225
return ResponseEntity.status(exceptionType.getStatus())
2326
.body(ResponseUtil.createFailureResponse(exceptionType));
2427

src/main/java/com/babzip/backend/global/jwt/JwtAuthenticationFilter.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010
import jakarta.servlet.http.HttpServletRequest;
1111
import jakarta.servlet.http.HttpServletResponse;
1212
import lombok.RequiredArgsConstructor;
13+
import org.slf4j.Logger;
14+
import org.slf4j.LoggerFactory;
1315
import org.springframework.http.HttpHeaders;
1416
import org.springframework.security.authentication.AuthenticationManager;
1517
import org.springframework.security.core.Authentication;
@@ -29,9 +31,17 @@ public class JwtAuthenticationFilter extends OncePerRequestFilter {
2931
private static final String BEARER_PREFIX = "Bearer ";
3032
private final AuthenticationManager authenticationManager;
3133
private final RequestMatcher requestMatcher = new RequestHeaderRequestMatcher(HttpHeaders.AUTHORIZATION);
34+
private static final Logger log = LoggerFactory.getLogger(JwtAuthenticationFilter.class);
35+
3236

3337
@Override
3438
protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response, FilterChain filterChain) throws ServletException, IOException {
39+
40+
String method = request.getMethod();
41+
String uri = request.getRequestURI();
42+
43+
log.info("🔍 API 요청: {} {}", method, uri);
44+
3545
// Authorization 헤더가 있을 때만 필터를 거쳐감
3646
// 인증이 필요없는 작업은 이 필터를 거치지 않음
3747
if (!requestMatcher.matches(request)) {

src/main/java/com/babzip/backend/guestbook/controller/GuestbookController.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
import com.babzip.backend.guestbook.dto.response.GuestbookSearchResponse;
1010
import com.babzip.backend.guestbook.service.GuestbookService;
1111
import lombok.RequiredArgsConstructor;
12+
import lombok.extern.slf4j.Slf4j;
1213
import org.springframework.data.domain.Page;
1314
import org.springframework.data.domain.Pageable;
1415
import org.springframework.data.domain.Sort;
@@ -20,6 +21,7 @@
2021
@RequiredArgsConstructor
2122
@RestController
2223
@RequestMapping("/guestbook")
24+
@Slf4j
2325
public class GuestbookController implements GuestBookApi {
2426

2527
private final GuestbookService guestbookService;
@@ -53,6 +55,7 @@ public ResponseEntity<ResponseBody<Void>> updatePartial(
5355
@RequestBody GuestbookRequestDto requestDto
5456
) {
5557
guestbookService.updatePartial(userId, requestDto);
58+
log.info("정상 작동");
5659
return ResponseEntity.ok(ResponseUtil.createSuccessResponse());
5760
}
5861

src/main/java/com/babzip/backend/guestbook/service/GuestbookService.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,15 @@
1111
import com.babzip.backend.user.repository.UserRepository;
1212
import jakarta.persistence.EntityNotFoundException;
1313
import lombok.RequiredArgsConstructor;
14+
import lombok.extern.slf4j.Slf4j;
1415
import org.springframework.data.domain.Page;
1516
import org.springframework.data.domain.Pageable;
1617
import org.springframework.stereotype.Service;
1718
import org.springframework.transaction.annotation.Transactional;
1819

1920
@RequiredArgsConstructor
2021
@Service
22+
@Slf4j
2123
public class GuestbookService {
2224

2325
private final GuestbookRepository guestbookRepository;
@@ -47,7 +49,9 @@ public Page<GuestbookResponseDto> getByUserId(Long userId, Pageable pageable) {
4749
public void updatePartial(Long userId, GuestbookRequestDto dto) {
4850
Guestbook guestbook = guestbookRepository.findByKakaoPlaceIdAndUserId(dto.kakaoPlaceId(), userId)
4951
.orElseThrow(() -> new BusinessException(ExceptionType.GUEST_BOOK_NOT_FOUND));
52+
log.info("정상 작동");
5053
guestbook.updatePartial(dto.restaurantName(), dto.kakaoPlaceId(), dto.content(), dto.rating());
54+
log.info("정상 작동");
5155
}
5256

5357
@Transactional

0 commit comments

Comments
 (0)