From d2be8f61ead90a8de4376b0dd800794d5ba9a061 Mon Sep 17 00:00:00 2001 From: kunsanglee Date: Fri, 9 Aug 2024 22:45:32 +0900 Subject: [PATCH] =?UTF-8?q?feat:=20actuator=20health=20=EC=97=94=EB=93=9C?= =?UTF-8?q?=ED=8F=AC=EC=9D=B8=ED=8A=B8=20=EC=84=A4=EC=A0=95=20=EB=B3=80?= =?UTF-8?q?=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../haengdong/HaengdongApplication.java | 1 - .../exception/GlobalExceptionHandler.java | 20 ++++++++++++++----- .../exception/HaengdongErrorCode.java | 1 + .../presentation/EventController.java | 2 -- server/src/main/resources/application.yml | 2 +- server/src/main/resources/logback-spring.xml | 3 ++- 6 files changed, 19 insertions(+), 10 deletions(-) diff --git a/server/src/main/java/server/haengdong/HaengdongApplication.java b/server/src/main/java/server/haengdong/HaengdongApplication.java index 0072a5a11..4a84c6120 100644 --- a/server/src/main/java/server/haengdong/HaengdongApplication.java +++ b/server/src/main/java/server/haengdong/HaengdongApplication.java @@ -9,7 +9,6 @@ public class HaengdongApplication { public static void main(String[] args) { - log.error("################### 안녕하세요. CI/CD 테스트입니다. ###################"); SpringApplication.run(HaengdongApplication.class, args); } diff --git a/server/src/main/java/server/haengdong/exception/GlobalExceptionHandler.java b/server/src/main/java/server/haengdong/exception/GlobalExceptionHandler.java index 026ee3452..7ed01c3c6 100644 --- a/server/src/main/java/server/haengdong/exception/GlobalExceptionHandler.java +++ b/server/src/main/java/server/haengdong/exception/GlobalExceptionHandler.java @@ -17,25 +17,35 @@ public class GlobalExceptionHandler { @ExceptionHandler(AuthenticationException.class) public ResponseEntity authenticationException(AuthenticationException e) { + log.warn(e.getMessage(), e); return ResponseEntity.status(HttpStatus.UNAUTHORIZED) .body(ErrorResponse.of(e.getErrorCode())); } - @ExceptionHandler({HttpRequestMethodNotSupportedException.class, NoResourceFoundException.class}) - public ResponseEntity noResourceException() { + @ExceptionHandler(HttpRequestMethodNotSupportedException.class) + public ResponseEntity noResourceException(HttpRequestMethodNotSupportedException e) { + log.warn(e.getMessage(), e); + return ResponseEntity.badRequest() + .body(ErrorResponse.of(HaengdongErrorCode.REQUEST_METHOD_NOT_SUPPORTED)); + } + + @ExceptionHandler(NoResourceFoundException.class) + public ResponseEntity noResourceException(NoResourceFoundException e) { + log.warn(e.getMessage(), e); return ResponseEntity.badRequest() .body(ErrorResponse.of(HaengdongErrorCode.NO_RESOURCE_REQUEST)); } @ExceptionHandler(HttpMessageNotReadableException.class) - public ResponseEntity httpMessageNotReadableException() { + public ResponseEntity httpMessageNotReadableException(HttpMessageNotReadableException e) { + log.warn(e.getMessage(), e); return ResponseEntity.badRequest() .body(ErrorResponse.of(HaengdongErrorCode.MESSAGE_NOT_READABLE)); } @ExceptionHandler(MethodArgumentNotValidException.class) public ResponseEntity handleMethodArgumentNotValidException(MethodArgumentNotValidException e) { - log.info(e.getMessage(), e); + log.warn(e.getMessage(), e); String errorMessage = e.getFieldErrors().stream() .map(error -> error.getField() + " " + error.getDefaultMessage()) .collect(Collectors.joining(", ")); @@ -46,7 +56,7 @@ public ResponseEntity handleMethodArgumentNotValidException(Metho @ExceptionHandler(HaengdongException.class) public ResponseEntity haengdongException(HaengdongException e) { - log.info(e.getMessage(), e); + log.warn(e.getMessage(), e); return ResponseEntity.badRequest() .body(ErrorResponse.of(e.getErrorCode())); } diff --git a/server/src/main/java/server/haengdong/exception/HaengdongErrorCode.java b/server/src/main/java/server/haengdong/exception/HaengdongErrorCode.java index 8af8d31e5..4020879d2 100644 --- a/server/src/main/java/server/haengdong/exception/HaengdongErrorCode.java +++ b/server/src/main/java/server/haengdong/exception/HaengdongErrorCode.java @@ -53,6 +53,7 @@ public enum HaengdongErrorCode { /* System */, MESSAGE_NOT_READABLE("읽을 수 없는 요청입니다."), + REQUEST_METHOD_NOT_SUPPORTED("지원하지 않는 요청 메서드입니다."), NO_RESOURCE_REQUEST("존재하지 않는 자원입니다."), INTERNAL_SERVER_ERROR("서버 내부에서 에러가 발생했습니다."); diff --git a/server/src/main/java/server/haengdong/presentation/EventController.java b/server/src/main/java/server/haengdong/presentation/EventController.java index 0f181c2db..54de966e5 100644 --- a/server/src/main/java/server/haengdong/presentation/EventController.java +++ b/server/src/main/java/server/haengdong/presentation/EventController.java @@ -36,8 +36,6 @@ public class EventController { @PostMapping("/api/events") public ResponseEntity saveEvent(@Valid @RequestBody EventSaveRequest request) { - log.error("################### 안녕하세요. CI/CD 테스트입니다. ###################"); - EventResponse eventResponse = EventResponse.of(eventService.saveEvent(request.toAppRequest())); String jwtToken = authService.createToken(eventResponse.eventId()); diff --git a/server/src/main/resources/application.yml b/server/src/main/resources/application.yml index 425a2c5a0..d6e34fc2f 100644 --- a/server/src/main/resources/application.yml +++ b/server/src/main/resources/application.yml @@ -39,7 +39,7 @@ management: endpoints: web: exposure: - include: logfile, metrics + include: health, metrics, logfile logging: level: diff --git a/server/src/main/resources/logback-spring.xml b/server/src/main/resources/logback-spring.xml index 204130e8c..7fa3da153 100644 --- a/server/src/main/resources/logback-spring.xml +++ b/server/src/main/resources/logback-spring.xml @@ -6,7 +6,8 @@ 30 - %d{yyyy-MM-dd HH:mm:ss} - %msg%n + + %d{yyyy-MM-dd HH:mm:ss} [%thread] %-5level %logger{36} - %msg%n