不少同学遇到有时候命名打印了错误日志却没有详细错误输出的问题,我们来测试一下:
public static void main(String[] args) {
try {
int a = 1/0;
} catch (Exception e) {
//第一种
log.error("AttentionServiceImpl--> wechatService.getAttention error, e:{}", e);
//第二种
log.error("AttentionServiceImpl--> wechatService.getAttention error, e.getMessage:{}", e.getMessage());
log.error("AttentionServiceImpl--> wechatService.getAttention error, e.getMessage:{},e:{}", e.getMessage(), e);
}
打印如下:
通过结果我们会发现, 要想打印出详细堆栈信息,我们得按第一种写法:
log.error("AttentionServiceImpl--> wechatService.getAttention error, e:{}", e);
公众号搜索: 果酱桑, 一起学习,一起成长!