在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);
}
}
e.printStackTrace();直接输出到System.err
log.error("error:",e);做了很多其他的处理,性能自然没那么高了,而且log可以通过配置的方式,输出到System.err,File,甚至是直接入库
e.printStackTrace(); 是输出在控制台
log.error("error:",e);可以输出到日志