当前位置:网站首页>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());
边栏推荐
- Penetration tools - trustedsec's penetration testing framework (PTF)
- Oracle 死锁测试
- 新牛牛盲盒微信小程序源码_支持流量变现,带完整素材图片
- 【let var const】
- Develop those things: easycvr cluster device management page function display optimization
- Iframe 父子页面通信
- math_ Use differentiation to calculate approximate value
- There are four ways to write switch, you know
- Richview trvdocparameters page parameter settings
- 独家消息:阿里云悄然推出RPA云电脑,已与多家RPA厂商开放合作
猜你喜欢

Uniapp uses Tencent map to select points without window monitoring to return users' location information. How to deal with it

Richview trvdocparameters page parameter settings

Solve the problem of slow or failed vscode download

运动捕捉系统原理

GaussDB(for MySQL) :Partial Result Cache,通过缓存中间结果对算子进行加速

STC 32-bit 8051 single chip microcomputer development example tutorial three program compilation setting and download

On the next generation entrance of the metauniverse -- the implementation of brain computer interface

王者战力查询改名工具箱小程序源码-带流量主激励广告

What if the win11 shortcut key switching input method doesn't respond? Shortcut key switching input method does not respond

Vulnerability recurrence - Net ueeditor upload
随机推荐
Interesting! Database is also serverless!
王者战力查询改名工具箱小程序源码-带流量主激励广告
EURA eurui E1000 series inverter uses PID to realize the relevant parameter setting and wiring of constant pressure water supply function
EDA工具对芯片产业的重要性知识科普
Common components of flask
[mysql] install mysql5.7
Summary of SQL aggregate query method for yyds dry goods inventory
Architect graduation summary
Use Zadig to build a continuous delivery platform from 0 to 1
internship:逐渐迈向项目开发
渗透工具-TrustedSec 公司的渗透测试框架 (PTF)
深度学习 神经网络基础
Learn white box test case design from simple to deep
Richview trvdocparameters page parameter settings
Problems encountered in installing MySQL in docker Ubuntu container
关联线探究,如何连接流程图的两个节点
ORA-01950
由浅入深学会白盒测试用例设计
利用QEventLoop实现同步等待槽函数返回
2022年高处安装、维护、拆除考题模拟考试平台操作