日志处理
This commit is contained in:
@@ -4,6 +4,7 @@ package com.cool.store.handler;
|
|||||||
import com.cool.store.exception.ApiException;
|
import com.cool.store.exception.ApiException;
|
||||||
import com.cool.store.exception.ServiceException;
|
import com.cool.store.exception.ServiceException;
|
||||||
import com.cool.store.response.error.ErrorResponse;
|
import com.cool.store.response.error.ErrorResponse;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.springframework.http.HttpStatus;
|
import org.springframework.http.HttpStatus;
|
||||||
import org.springframework.http.ResponseEntity;
|
import org.springframework.http.ResponseEntity;
|
||||||
import org.springframework.web.bind.annotation.ExceptionHandler;
|
import org.springframework.web.bind.annotation.ExceptionHandler;
|
||||||
@@ -15,23 +16,27 @@ import org.springframework.web.bind.annotation.RestControllerAdvice;
|
|||||||
* @Description: 自定义异常处理
|
* @Description: 自定义异常处理
|
||||||
* @date 2023-06-13 19:42
|
* @date 2023-06-13 19:42
|
||||||
*/
|
*/
|
||||||
|
@Slf4j
|
||||||
@RestControllerAdvice
|
@RestControllerAdvice
|
||||||
public class CustomExceptionHandler {
|
public class CustomExceptionHandler {
|
||||||
|
|
||||||
@ExceptionHandler(value = ServiceException.class)
|
@ExceptionHandler(value = ServiceException.class)
|
||||||
public ResponseEntity<ErrorResponse> handleCustomException(ServiceException e) {
|
public ResponseEntity<ErrorResponse> handleCustomException(ServiceException e) {
|
||||||
|
log.error(e.getMessage(), e);
|
||||||
ErrorResponse errorResponse = new ErrorResponse(e.getErrorCode(), e.getMessage());
|
ErrorResponse errorResponse = new ErrorResponse(e.getErrorCode(), e.getMessage());
|
||||||
return new ResponseEntity<>(errorResponse, HttpStatus.BAD_REQUEST);
|
return new ResponseEntity<>(errorResponse, HttpStatus.BAD_REQUEST);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ExceptionHandler(value = ApiException.class)
|
@ExceptionHandler(value = ApiException.class)
|
||||||
public ResponseEntity<ErrorResponse> handleCustomException(ApiException e) {
|
public ResponseEntity<ErrorResponse> handleCustomException(ApiException e) {
|
||||||
|
log.error(e.getMessage(), e);
|
||||||
ErrorResponse errorResponse = new ErrorResponse(e.getErrorCode(), e.getMessage());
|
ErrorResponse errorResponse = new ErrorResponse(e.getErrorCode(), e.getMessage());
|
||||||
return new ResponseEntity<>(errorResponse, HttpStatus.BAD_REQUEST);
|
return new ResponseEntity<>(errorResponse, HttpStatus.BAD_REQUEST);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ExceptionHandler(value = Exception.class)
|
@ExceptionHandler(value = Exception.class)
|
||||||
public ResponseEntity<ErrorResponse> handleException(Exception e) {
|
public ResponseEntity<ErrorResponse> handleException(Exception e) {
|
||||||
|
log.error(e.getMessage(), e);
|
||||||
ErrorResponse errorResponse = new ErrorResponse(HttpStatus.INTERNAL_SERVER_ERROR.value(), e.getMessage());
|
ErrorResponse errorResponse = new ErrorResponse(HttpStatus.INTERNAL_SERVER_ERROR.value(), e.getMessage());
|
||||||
return new ResponseEntity<>(errorResponse, HttpStatus.INTERNAL_SERVER_ERROR);
|
return new ResponseEntity<>(errorResponse, HttpStatus.INTERNAL_SERVER_ERROR);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -41,7 +41,7 @@
|
|||||||
</encoder>
|
</encoder>
|
||||||
</appender>
|
</appender>
|
||||||
|
|
||||||
<logger name="com.cool.store.mapper" level="DEBUG" additivity="true" />
|
<logger name="com.cool.store.mapper" level="DEBUG" additivity="true" />
|
||||||
<!--灰度、线上、预防 不输出到console-->
|
<!--灰度、线上、预防 不输出到console-->
|
||||||
<springProfile name="hd,online,pre">
|
<springProfile name="hd,online,pre">
|
||||||
<root level="info">
|
<root level="info">
|
||||||
|
|||||||
Reference in New Issue
Block a user