效果图:
需求:
**
错误弹窗的数据内容:bug原因+bug定位
**
后端代码:
try {
//略
} catch (Exception e) {
log.error("系统错误!"+e.getMessage()+",paramMap:"+JSON.toJSONString(paraMap),e);
StringWriter stringWriter=new StringWriter();
//获取缓冲区的数据信息
e.printStackTrace(new PrintWriter(stringWriter));
//从字符输入流中读取文本并缓冲字符
BufferedReader bufferedReader=new BufferedReader(new StringReader(stringWriter.getBuffer().toString()));
StringWriter stringWriterDest=new StringWriter();
stringWriterDest.append("<pre>系统错误!"+e.getMessage());
stringWriterDest.append("\r\n");
bufferedReader.lines().forEach(
s -> {
//不输出所有日志,只定位到错误日志位置
if(stringWriterDest.getBuffer().indexOf(this.getClass().getPackage().toString().replace("package ",""))==-1){
stringWriterDest.append(s);
stringWriterDest.append("\r\n");
}
}
);
stringWriterDest.append("paramMap:"+ JSON.toJSONString(paraMap));
stringWriterDest.append("</pre>");
HashMap<String, Object> result = createResult(false, "操作失败");
result.put("log", stringWriterDest.toString());
log.error("系统错误!" + e.getMessage(), e);
return result;
}
前端代码:
if (data.success) {
hstable(data.list,true)
}else {
layer.open({
area: ['600px', '400px'],
content: '<div style=" width: 550px;height: 380px; ">'+ data.log +'</div>' //这里content是一个普通的String
});
hstable([],true)
}