输出异常到日志 博客分类: Java log4jException输出日志StackTraceElemente.getStackTrace
程序员文章站
2024-03-11 15:38:55
...
public static void writeException(Exception e) { if (e == null) { log.error("unknown error"); return; } try { StackTraceElement[] s = e.getStackTrace(); StringBuffer em = new StringBuffer(e.getMessage()); if (s != null) { for (int i = 0; i < s.length; i++) { StackTraceElement st = s[i]; em.append("\t\t").append(st.toString()).append("\r\n"); } } log.error(em.toString()); } catch (Exception e1) { e1.printStackTrace(); } }