We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
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
目前createLog方法中LogDTO.exception获取的仅为e.getMessage(),而我想获取的是e.printStackTrace()的内容。
createLog
LogDTO.exception
e.getMessage()
e.printStackTrace()
大多项目都会有一个全局异常处理。 GlobalExceptionHandler:
GlobalExceptionHandler
/** * 全局异常处理 */ @Slf4j @ControllerAdvice public class GlobalExceptionHandler { @ExceptionHandler(value = Exception.class) @ResponseBody public ApiResponse<String> handlerException(Exception e) { StringWriter sw = new StringWriter(); PrintWriter pw = new PrintWriter(sw); e.printStackTrace(pw); LogRecordContext.putVariable("exception", sw.toString()); // …… }
上文代码中的LogRecordContext.putVariable("exception", sw.toString());仅为我的猜想,能否通过这种方式去设置LogDTO.exception的值(put 中可以特殊点叫 $exception 或者加新方法),不然每个@OperationLog都要加属性(当然现在还没有可以配置exception的属性)。
LogRecordContext.putVariable("exception", sw.toString());
@OperationLog
exception
假设可以自定义LogDTO.exception的值的话,GlobalExceptionHandler.handlerException的执行顺序也总是在createLog方法后,@Order注解无效。或者 LogDTO 可以获取到 Exception 对象也行。
GlobalExceptionHandler.handlerException
@Order
The text was updated successfully, but these errors were encountered:
收到了
Sorry, something went wrong.
这个现在有解决方案吗?我也遇到了同样的问题
No branches or pull requests
目前
createLog
方法中LogDTO.exception
获取的仅为e.getMessage()
,而我想获取的是e.printStackTrace()
的内容。大多项目都会有一个全局异常处理。
GlobalExceptionHandler
:上文代码中的
LogRecordContext.putVariable("exception", sw.toString());
仅为我的猜想,能否通过这种方式去设置LogDTO.exception
的值(put 中可以特殊点叫 $exception 或者加新方法),不然每个@OperationLog
都要加属性(当然现在还没有可以配置exception
的属性)。假设可以自定义
LogDTO.exception
的值的话,GlobalExceptionHandler.handlerException
的执行顺序也总是在createLog
方法后,@Order
注解无效。或者 LogDTO 可以获取到 Exception 对象也行。The text was updated successfully, but these errors were encountered: