输出异常到日志

阅读更多
	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();
		}
	}

 

你可能感兴趣的:(log4j,Exception,输出日志,e.getStackTrace)