杀生丸H 2022-09-29 14:34 采纳率: 0%
浏览 89

e.printStackTrace与log.error(e)区别

问题遇到的现象和发生背景

在try{}catch(){}中直接exception.printStackTrace();与log.error(exception)除了输出位置不同之外有没有其他区别?
比如输出结果上或者性能上

用代码块功能插入代码,请勿粘贴截图

public static void main(String[] args) {
try {
String txt = "";
String substring = txt.substring(1, 2);
} catch (Exception e) {
e.printStackTrace();
log.error("error:",e);
}
}

  • 写回答

3条回答 默认 最新

  • 游一游走一走 2022-09-29 14:51
    关注

    e.printStackTrace();直接输出到System.err
    log.error("error:",e);做了很多其他的处理,性能自然没那么高了,而且log可以通过配置的方式,输出到System.err,File,甚至是直接入库

    评论

报告相同问题?

问题事件

  • 创建了问题 9月29日