Java工具类:
public class ExceptionConstans { public static String getTrace(Throwable t) { StringWriter stringWriter= new StringWriter(); PrintWriter writer= new PrintWriter(stringWriter); t.printStackTrace(writer); StringBuffer buffer= stringWriter.getBuffer(); return buffer.toString(); } }
程序里调用:
log.error("/n异常信息如下:/n" + ExceptionConstans.getTrace(e));
或:
log.error("/n异常信息如下:/n" + ExceptionUtils.getFullStackTrace(e));