当前位置:网站首页>Slf4j打印异常的堆栈信息
Slf4j打印异常的堆栈信息
2022-07-01 19:09:00 【紫金小飞侠】
SLF4J 1.6.0之前版本
只有这样写才会打印错误堆栈
logger.error(String msg, Throwable t);------>logger.error(e.getMessage(),e);
或者
logger.info(String msg, Throwable t);------>logger.info(e.getMessage(),e);
@GetMapping("/test")
public String test(){
try {
int i = 1/0;
} catch (Exception e) {
log.error(" 异常信息", e);
}
}
所以SLF4J 1.6.0之前版本 一般用String.format方法格式化msg。
SLF4J 1.6.0版本之后,
error(String format, Object... arguments)
info(String format, Object... arguments)
正常写也会打印异常堆栈信息,只不过规定Throwable对象必须为最后一个参数.如果不遵守这个规定,异常堆栈信息不会打印出来。
注意e不需要{},前面加了就不会打印堆栈信息了
要这样写:
log.error(" 异常信息t:{},id:{}.", e.getMessage(),"1234567", e);
不能这样写:
log.error(" 异常信息t:{},id:{}, e:{}", e.getMessage(),"1234567", e);
@GetMapping("/test")
public String test(){
try {
int i = 1/0;
} catch (Exception e) {
log.error(" 异常信息t:{},id:{}.", e.getMessage(),"1234567", e);
}
return "=========get test success!========";
}

以下方式也不会打印堆栈信息
log.error(" 异常信息getStackTrace:{}“, e.getStackTrace());
log.error(” 异常信息toString:{}", e.toString());
边栏推荐
- Develop those things: easycvr platform adds playback address authentication function
- Penetration tools - trustedsec's penetration testing framework (PTF)
- Win11怎么关闭开机自启动软件
- cocoaPods 添加成功后,导入不了头文件或者not found file 报错
- 三菱PLC FX3U脉冲轴点动功能块(MC_Jog)
- Stack Overflow 2022 开发者调查:行业走向何方?
- Flask 常用组件
- RichView 文档中的 ITEM
- RichView RichEdit SRichViewEdit PageSize 页面设置与同步
- Keras机器翻译实战
猜你喜欢

Data analysts sound tall? Understand these points before you decide whether to transform

Win11快捷键切换输入法无反应怎么办?快捷键切换输入法没有反应

Exclusive news: Alibaba cloud quietly launched RPA cloud computer and has opened cooperation with many RPA manufacturers

1592 example 1 King (sgu223 loj10170 luogu1896 increase + / provincial election -) violent thinking pressure DP 01 Backpack

RichView 文档中的 ITEM
![[mysql] install mysql5.7](/img/c4/d7fb5ddf8e7be31f7a9ad68409e584.png)
[mysql] install mysql5.7

fastDFS入门

目标检测——Yolo系列

Test of NSI script

EURA欧瑞E1000系列变频器使用PID实现恒压供水功能的相关参数设置及接线
随机推荐
On the next generation entrance of the metauniverse -- the implementation of brain computer interface
Oracle deadlock test
极客DIY开源方案分享——数字幅频均衡功率放大器设计(实用的嵌入式电子设计作品软硬件综合实践)
2022熔化焊接与热切割上岗证题目模拟考试平台操作
Vulnerability recurrence - Net ueeditor upload
internship:复杂json格式数据编写接口
Richview RichEdit srichviewedit PageSize page setup and synchronization
What if the win11 shortcut key switching input method doesn't respond? Shortcut key switching input method does not respond
C#聯合halcon應用——大華相機采集類
独家消息:阿里云悄然推出RPA云电脑,已与多家RPA厂商开放合作
Entering Ruxin Town, digital intelligence transformation connects "future community"
Stack Overflow 2022 开发者调查:行业走向何方?
300 linear algebra Lecture 4 linear equations
Win11如何取消任务栏隐藏?Win11取消任务栏隐藏的方法
Win11暂停更新点不了怎么办?Win11暂停更新是灰色的如何解决?
牛客编程题--必刷101之字符串(高效刷题,举一反三)
Write blog documents
[C language] explain the usage of memset() function in detail
Solve the problem of slow or failed vscode download
#yyds干货盘点#SQL聚合查询方法总结