public static void main(String[] args) {
int a = 10;
try {
int i = 1/0;
}
catch (Exception e) {
System.out.println("--------------------");
e.printStackTrace();// 只能输出在控制台当中,日志文件看不到
System.out.println("--------------------");
log.error(e.getMessage());// 只能输出简短的错误信息,不便于排错
System.out.println("--------------------");
log.error(e.getStackTrace().toString());// 不能输出错误信息
System.out.println("--------------------");
log.error("需要在错误日志 error 之上打锚点,报错了,a-{}",a);
//用这个去打印日志,完整的日志信息会被打印在日志之中,相当于 e.printStackTrace();
log.error("test fail-",e);// 可以在日志中输出完整的错误信息,""里要写内容,不能在此处去打错误锚点(不能使用log.error("test fail-{},{}",a,e))无法打出全部日志
System.out.println("--------------------");
log.error("test fail-{},{}",a,e);//无法打出全部日志
System.out.println("--------------------");
log.error(e.toString());// 只能输出简短的错误信息,不便于排错
}
}
--------------------
java.lang.ArithmeticException: / by zero
at com.jn.ssr.superrescue.web.order.service.impl.OrderBasicServiceImpl.main(OrderBasicServiceImpl.java:)
main 2019.11. at ::51.331 CST [] ERROR com.jn.ssr.superrescue.web.order.service.impl.OrderBasicServiceImpl main(): - / by zero
--------------------
main 2019.11. at ::51.350 CST [] ERROR com.jn.ssr.superrescue.web.order.service.impl.OrderBasicServiceImpl main(): - [Ljava.lang.StackTraceElement;@5fd4f8f5
--------------------
main 2019.11. at ::51.356 CST [] ERROR com.jn.ssr.superrescue.web.order.service.impl.OrderBasicServiceImpl main(): - 需要在错误日志 error 之上打锚点,报错了,a-
main 2019.11. at ::51.357 CST [] ERROR com.jn.ssr.superrescue.web.order.service.impl.OrderBasicServiceImpl main(): - test fail-
java.lang.ArithmeticException: / by zero
at com.jn.ssr.superrescue.web.order.service.impl.OrderBasicServiceImpl.main(OrderBasicServiceImpl.java:) [classes/:?]
--------------------
main 2019.11. at ::51.365 CST [] ERROR com.jn.ssr.superrescue.web.order.service.impl.OrderBasicServiceImpl main(): - test fail-,java.lang.ArithmeticException: / by zero
--------------------
main 2019.11. at ::51.366 CST [] ERROR com.jn.ssr.superrescue.web.order.service.impl.OrderBasicServiceImpl main(): - java.lang.ArithmeticException: / by zero
05-16 08:53