@RestControllerAdvice
@Slf4j
public class GlobalException {
    @ExceptionHandler(ServiceException.class)
    public String serviceExceptionHandler(ServiceException e) {
        StackTraceElement stackTraceElement = e.getStackTrace()[0];
        // 获取类名
        String className = stackTraceElement.getClassName();
        String filePath = stackTraceElement.getFileName();
        int lineNumber = stackTraceElement.getLineNumber();
        String methodName = stackTraceElement.getMethodName();
        log.info("类名:{},文件路径:{},行数:{},方法名:{}", className, filePath , lineNumber, methodName);
        return "类名:" + className + ",文件路径:" + filePath + ",行数:" + lineNumber + "方法名:" + methodName;
    }
}

Zeran
32 声望4 粉丝

学而不思则罔,思而不学则殆。