当前位置:网站首页>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());
边栏推荐
- Understand the structure in C language in one article
- 如何用OpenMesh创建一个四棱锥
- Détection des cibles - série Yolo
- After adding cocoapods successfully, the header file cannot be imported or an error is reported in not found file
- 如果浏览器被意外关闭,react怎么缓存用户填写的表单?
- Detailed explanation and code example of affinity propagation clustering calculation formula based on graph
- 网上开户是安全的吗?新手可以开炒股账户吗。
- How to connect the two nodes of the flow chart
- What did you learn about cheating after you went to college?
- 运动捕捉系统原理
猜你喜欢

《軟件工程導論(第六版)》 張海藩 複習筆記

cocoaPods 添加成功后,导入不了头文件或者not found file 报错

关于元宇宙下一代入口——脑机接口的实现

300题线性代数 第四讲 线性方程组

STC 32位8051单片机开发实例教程 三 程序编译设置与下载

小鸟逃票登机,如何反思,应如何解决,飞机为何怕小鸟?

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

使用Zadig从0到1搭建持续交付平台

渗透工具-TrustedSec 公司的渗透测试框架 (PTF)

Big factories are wolves, small factories are dogs?
随机推荐
C#联合halcon应用——大华相机采集类
uniapp使用腾讯地图选点 没有window监听回传用户的位置信息,怎么处理
Win11快捷键切换输入法无反应怎么办?快捷键切换输入法没有反应
fastDFS入门
2022年高处安装、维护、拆除考题模拟考试平台操作
编译原理复习笔记
2022安全员-B证考试练习题模拟考试平台操作
Arduino Stepper库驱动28BYJ-48步进电机测试程序
升级版手机检测微信工具小程序源码-支持多种流量主模式
Oracle deadlock test
Using qeventloop to realize synchronous waiting for the return of slot function
Write blog documents
Past and present life of product modular design
How to connect the two nodes of the flow chart
Principle of motion capture system
300 linear algebra Lecture 4 linear equations
GaussDB(for MySQL) :Partial Result Cache,通过缓存中间结果对算子进行加速
Entering Ruxin Town, digital intelligence transformation connects "future community"
Understand the structure in C language in one article
利用QEventLoop实现同步等待槽函数返回