優化自定義的Exception的日誌列印,設定自定義使用的ApiException extends Exception日誌列印不刷出堆疊資訊配置程式碼ApiException類即可

君子志邦發表於2020-11-03

1、ApiException extends Exception類的定義實現

public class ApiException extends Exception  {

    private static final long serialVersionUID = 1256016620875694495L;

    private int code;

    private String msg;

    public ApiException(int code, String msg){
        super(msg);
        this.code = code;
        this.msg = msg;
    }

    public int getCode() {
        return code;
    }

    public void setCode(int code) {
        this.code = code;
    }

    public String getMsg() {
        return msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }
    // 關鍵
    @Override
    public Throwable fillInStackTrace() {
        return this;
    }


}

2、

2020-11-03 10:47:11.065|ERROR|JRESHandler-2.0.1.47:12301-thread-56|18|c.h.j.common.log.bizerr.BizerrLog       :{"type":"5","info":["","","","","2020-11-03 10:47:11.065","tbm-compose-provider","2.0.1.47","1","","","com.api.facade.HandleFacade.getNextList","jres-svr",""],"myPackage":{"error_no":"-1","error_info":"該查詢條件下已經沒有下一條資訊了!","requestBody":"","exceptionStack":"com.api.exception.ApiException: 該查詢條件下已經沒有下一條資訊了!

"}}

相關文章