当前位置:网站首页>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());
边栏推荐
- What if win11 can't pause the update? Win11 pause update is gray. How to solve it?
- Use Zadig to build a continuous delivery platform from 0 to 1
- [mysql] install mysql5.7
- 【C语言】详解 memset() 函数用法
- How to connect the two nodes of the flow chart
- Win11怎么关闭开机自启动软件
- Richview trvdocparameters page parameter settings
- 《软件工程导论(第六版)》 张海藩 复习笔记
- C#联合halcon应用——大华相机采集类
- uniapp使用腾讯地图选点 没有window监听回传用户的位置信息,怎么处理
猜你喜欢
STC 32-bit 8051 single chip microcomputer development example tutorial three program compilation setting and download
Uniapp uses Tencent map to select points without window monitoring to return users' location information. How to deal with it
Win11怎么关闭开机自启动软件
Principle of motion capture system
A quietly rising domestic software, low-key and powerful!
What if win11 can't pause the update? Win11 pause update is gray. How to solve it?
3D全景模型展示可视化技术演示
uniapp使用腾讯地图选点 没有window监听回传用户的位置信息,怎么处理
数据分析师听起来很高大上?了解这几点你再决定是否转型
由浅入深学会白盒测试用例设计
随机推荐
C#聯合halcon應用——大華相機采集類
喜马拉雅自研网关架构演进过程
实战项目笔记(一)——虚拟机的创建
C#联合halcon应用——大华相机采集类
[C language] explain the usage of memset() function in detail
渗透工具-TrustedSec 公司的渗透测试框架 (PTF)
math_利用微分算近似值
Oracle 死锁测试
On the usage of a magic function
利用QEventLoop实现同步等待槽函数返回
Oracle deadlock test
GaussDB(for MySQL) :Partial Result Cache,通过缓存中间结果对算子进行加速
EURA eurui E1000 series inverter uses PID to realize the relevant parameter setting and wiring of constant pressure water supply function
internship:复杂json格式数据编写接口
RichView 文档中的 ITEM
寫博客文檔
写博客文档
Problems encountered in installing MySQL in docker Ubuntu container
How to create a pyramid with openmesh
[Blue Bridge Cup web] analysis of the real topic of the 13th Blue Bridge Cup web university group match in 2022