这是AWS cloudwatch logger的一个已知问题,请参阅RichardBronosky的评论
https://github.com/visionmedia/debug/issues/296
我做了一些测试,发现CloudWatch日志条目可以是多行的
通过使用
\r
作为行分隔符。使用其中一个
\n
\r\n
(DOS)线
结尾将导致单独的条目
所以我添加了以下内容
ExceptionHandler
至弹簧靴
RestController
@ExceptionHandler(Throwable.class)
void handleUnhandledExceptions(Throwable e, HttpServletResponse response) throws IOException {
StringWriter buffer = new StringWriter();
e.printStackTrace(new PrintWriter(buffer));
log.error(buffer.toString().replace("\n", "\r"));
response.sendError(HttpStatus.INTERNAL_SERVER_ERROR.value(), e.getMessage());
}