From 825be64d6dd699ebd082dd2ef2444690c5f29bbf Mon Sep 17 00:00:00 2001 From: YunaiV Date: Fri, 19 Jul 2024 23:37:00 +0800 Subject: [PATCH] =?UTF-8?q?=E3=80=90=E5=8A=9F=E8=83=BD=E4=BC=98=E5=8C=96?= =?UTF-8?q?=E3=80=91=E5=85=A8=E5=B1=80=EF=BC=9A=E7=AE=80=E5=8C=96=20Global?= =?UTF-8?q?ExceptionHandler=20=E5=AF=B9=20ServiceException=20=E7=9A=84?= =?UTF-8?q?=E6=89=93=E5=8D=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../framework/web/core/handler/GlobalExceptionHandler.java | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/yudao-framework/yudao-spring-boot-starter-web/src/main/java/cn/iocoder/yudao/framework/web/core/handler/GlobalExceptionHandler.java b/yudao-framework/yudao-spring-boot-starter-web/src/main/java/cn/iocoder/yudao/framework/web/core/handler/GlobalExceptionHandler.java index 021858f42..6935f7bee 100644 --- a/yudao-framework/yudao-spring-boot-starter-web/src/main/java/cn/iocoder/yudao/framework/web/core/handler/GlobalExceptionHandler.java +++ b/yudao-framework/yudao-spring-boot-starter-web/src/main/java/cn/iocoder/yudao/framework/web/core/handler/GlobalExceptionHandler.java @@ -219,9 +219,11 @@ public class GlobalExceptionHandler { */ @ExceptionHandler(value = ServiceException.class) public CommonResult serviceExceptionHandler(ServiceException ex) { + // 不包含的时候,才进行打印,避免 ex 堆栈过多 if (!IGNORE_ERROR_MESSAGES.contains(ex.getMessage())) { - // 不包含的时候,才进行打印,避免 ex 堆栈过多 - log.info("[serviceExceptionHandler]", ex); + // 即使打印,也只打印第一层 StackTraceElement,并且使用 warn 在控制台输出,更容易看到 + StackTraceElement[] stackTrace = ex.getStackTrace(); + log.warn("[serviceExceptionHandler]\n\t{}", stackTrace[0]); } return CommonResult.error(ex.getCode(), ex.getMessage()); }