当前位置:网站首页>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());
边栏推荐
- Use of common built-in classes of JS
- 宅男壁纸大全微信小程序源码-带动态壁纸支持多种流量主
- Keras机器翻译实战
- GaussDB(for MySQL) :Partial Result Cache,通过缓存中间结果对算子进行加速
- How to prevent repeated submission of new orders
- Common components of flask
- Tensorflow reports an error, could not load dynamic library 'libcudnn so. eight
- Richview trvdocparameters page parameter settings
- 300题线性代数 第四讲 线性方程组
- What if the win11 shortcut key switching input method doesn't respond? Shortcut key switching input method does not respond
猜你喜欢

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

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

RichView TRVDocParameters 页面参数设置

强大、好用、适合程序员/软件开发者的专业编辑器/笔记软件综合评测和全面推荐

What if win11 can't pause the update? Win11 pause update is gray. How to solve it?

Niuke programming question -- must brush the string of 101 (brush the question efficiently, draw inferences from one instance)

喜马拉雅自研网关架构演进过程

RichView RichEdit SRichViewEdit PageSize 页面设置与同步

EURA欧瑞E1000系列变频器使用PID实现恒压供水功能的相关参数设置及接线

A quietly rising domestic software, low-key and powerful!
随机推荐
Detailed explanation and code example of affinity propagation clustering calculation formula based on graph
Richview RichEdit srichviewedit PageSize page setup and synchronization
C # joint halcon Application - Dahua Camera Collection class
Using qeventloop to realize synchronous waiting for the return of slot function
On the next generation entrance of the metauniverse -- the implementation of brain computer interface
docker ubuntu容器中安装mysql遇到的问题
Big factories are wolves, small factories are dogs?
internship:逐渐迈向项目开发
Review notes of Zhang Haifan in introduction to software engineering (Sixth Edition)
3D panoramic model display visualization technology demonstration
What else do you not know about new set()
Gaussdb (for MySQL):partial result cache, which accelerates the operator by caching intermediate results
漏洞复现-.Net-ueditor上传
STC 32位8051单片机开发实例教程 二 I/O工作模式及其配置
Win11快捷键切换输入法无反应怎么办?快捷键切换输入法没有反应
1592 example 1 King (sgu223 loj10170 luogu1896 increase + / provincial election -) violent thinking pressure DP 01 Backpack
运动捕捉系统原理
基于图的 Affinity Propagation 聚类计算公式详解和代码示例
寫博客文檔
switch 有四样写法你知道么