当前位置:网站首页>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());
边栏推荐
- Win11如何取消任务栏隐藏?Win11取消任务栏隐藏的方法
- 实战项目笔记(一)——虚拟机的创建
- There are four ways to write switch, you know
- EURA欧瑞E1000系列变频器使用PID实现恒压供水功能的相关参数设置及接线
- ORA-01950
- Myslq ten kinds of locks, an article will take you to fully analyze
- Error in installing sharp
- C # joint Halcon application - Dahua camera acquisition class
- 关于一个神奇函数的用法
- List is divided into sets that meet and do not meet conditions (partitioningby)
猜你喜欢
RichView 文档中的 ITEM
【多线程】 实现单例模式 ( 饿汉、懒汉 ) 实现线程安全的单例模式 (双重效验锁)
Data analysts sound tall? Understand these points before you decide whether to transform
[multithreading] lock strategy
Comprehensive evaluation and detailed inventory of high-quality note taking software (I) note, obsedian, remnote, flowus
3D全景模型展示可视化技术演示
大厂做狼,小厂做狗?
Error in installing sharp
Develop those things: easycvr platform adds playback address authentication function
2022安全员-A证考题及在线模拟考试
随机推荐
Win11怎么关闭开机自启动软件
深度学习 常见的损失函数
What else do you not know about new set()
基于图的 Affinity Propagation 聚类计算公式详解和代码示例
Items in richview documents
Uniapp uses Tencent map to select points without window monitoring to return users' location information. How to deal with it
运动捕捉系统原理
Using qeventloop to realize synchronous waiting for the return of slot function
2022安全员-B证考试练习题模拟考试平台操作
RichView TRVDocParameters 页面参数设置
架构师毕业总结
小鸟逃票登机,如何反思,应如何解决,飞机为何怕小鸟?
8K HDR!| Hevc hard solution for chromium - principle / Measurement Guide
Summary of SQL aggregate query method for yyds dry goods inventory
Iframe 父子页面通信
Keras machine translation practice
Myslq ten kinds of locks, an article will take you to fully analyze
EDA工具对芯片产业的重要性知识科普
C # joint Halcon application - Dahua camera acquisition class
NSI脚本的测试