大家知道 e.printStackTrace() 可以打印异常堆栈信息 ,那么 logger.error() 怎么输出呢
正确写法
try { } catch (ArgsException e) { logger.error("异常",e); }
错误写法
logger.error(e.getMessage());
logger.error(e.toString());
logger.error("异常" + e);
看源码
/** * Log a message at the ERROR level. * * @param msg the message string to be logged */ public void error(String msg);
/** * Log an exception (throwable) at the ERROR level with an * accompanying message. * * @param msg the message accompanying the exception * @param t the exception (throwable) to log */ public void error(String msg, Throwable t);
可以看出如果传入字符串是不会打印异常信息的