package cn.pluss.platform.util;

import org.slf4j.Logger;
import org.springframework.cglib.proxy.UndeclaredThrowableException;

import java.lang.reflect.InvocationTargetException;

/**
 * @author djh
 */
public class LogExceptionUtils {

    public static void printStack(Logger logger, Throwable e, String message) {
        logger.info("异常名称：{}", e.getClass().getCanonicalName());
        if (e instanceof UndeclaredThrowableException) {
            e.getCause().printStackTrace();
            logger.info(message , e.getCause().getMessage());
        } else if (e instanceof InvocationTargetException) {
            ((InvocationTargetException) e).getTargetException().printStackTrace();
            logger.info(message, e.getMessage());
        } else {
            e.printStackTrace();
            logger.info(message, e.getMessage());
        }
    }
}
