当前位置:网站首页>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());
边栏推荐
- Face recognition system opencv face detection
- Review notes of Zhang Haifan in introduction to software engineering (Sixth Edition)
- 1592 example 1 King (sgu223 loj10170 luogu1896 increase + / provincial election -) violent thinking pressure DP 01 Backpack
- Set object value changes null value object
- Customize the insertion of page labels and realize the initial search of similar address books
- 利用QEventLoop实现同步等待槽函数返回
- 人脸识别系统 —— OpenCV人脸检测
- EURA eurui E1000 series inverter uses PID to realize the relevant parameter setting and wiring of constant pressure water supply function
- Oracle deadlock test
- 《软件工程导论(第六版)》 张海藩 复习笔记
猜你喜欢

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

Target detection - Yolo series

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

Arduino Stepper库驱动28BYJ-48步进电机测试程序

Vulnerability recurrence - Net ueeditor upload

强大的万年历微信小程序源码-支持多做流量主模式

Detailed explanation and code example of affinity propagation clustering calculation formula based on graph

Customize the insertion of page labels and realize the initial search of similar address books

Solve the problem of slow or failed vscode download

Interesting! Database is also serverless!
随机推荐
PLC模拟量输入 模拟量转换FB S_ITR(三菱FX3U)
Importance of EDA tools to chip industry knowledge popularization
2022安全员-B证考试练习题模拟考试平台操作
王者战力查询改名工具箱小程序源码-带流量主激励广告
新牛牛盲盒微信小程序源码_支持流量变现,带完整素材图片
小鸟逃票登机,如何反思,应如何解决,飞机为何怕小鸟?
走进如心小镇,数智化变革连接“未来社区”
优质笔记软件综合评测和详细盘点(一) Notion、Obsidian、RemNote、FlowUs
Uniapp uses Tencent map to select points without window monitoring to return users' location information. How to deal with it
Win11暂停更新点不了怎么办?Win11暂停更新是灰色的如何解决?
如何用OpenMesh创建一个四棱锥
Iframe 父子页面通信
300 linear algebra Lecture 4 linear equations
【蓝桥杯Web】2022年第十三届蓝桥杯Web大学组国赛真题解析
深度学习 神经网络基础
Oracle 死锁测试
Niuke programming question -- must brush the string of 101 (brush the question efficiently, draw inferences from one instance)
Architect graduation summary
Past and present life of product modular design
Target detection - Yolo series