package cn.superdesk.uniorder.common.exception.utils;

import java.io.IOException;
import java.io.PrintWriter;
import java.io.StringWriter;

/**
 * @Description: 用于记录日志
 * @Author: linjinyu
 * @CreateDate: 2020/12/23 下午2:20
 * @UpdateUser: linjinyu
 * @UpdateDate: 2020/12/23 下午2:20
 * @UpdateRemark: 修改内容
 * @Version: 1.0
 */
public class ExceptionUtils {

	public static String getMessage(Exception e) {

		StringWriter stringWriter = null;
		PrintWriter  printWriter  = null;

		try {
			stringWriter = new StringWriter();
			printWriter = new PrintWriter(stringWriter);

			// 将出错的栈信息输出到printWriter中
			e.printStackTrace(printWriter);

			printWriter.flush();
			stringWriter.flush();

		} finally {

			if (stringWriter != null) {
				try {
					stringWriter.close();
				} catch (IOException e1) {
					e1.printStackTrace();
				}
			}

			if (printWriter != null) {
				printWriter.close();
			}
		}

		return stringWriter.toString();
	}
}