Logger跟Exception
Logger和Exception
public class PayException extends Exception { /** * */ private static final long serialVersionUID = 2373806520202646197L; /** * 异常消息号 */ private int msgId; /** * 一般性错误,依赖消息 */ public static final int NORMAL_ERROR = -1; /** * 登陆账号异常 */ public static final int YIXIN_ACCOUNTID_ERROR = -2; /** * 生成签名失败 */ public static final int GENERATE_SIGNATURE_FAIL = -3; /** * 验证签名失败 */ public static final int VERIFY_SIGNATURE_FAIL = -4; /** * 商品不存在 */ public static final int GOODS_NOT_EXIST = -5; /** * 订单不存在 */ public static final int TRADE_NOT_EXIST = -6; /** * 支付方式错误 */ public static final int PAYMETHOD_ERROR = -7; /** * 参数非法 */ public static final int PARAMETER_ILLEGAL = -8; /** * 超时 */ public static final int TIMEOUT_ERROR = -9; /** * 更新PayToolType失败 */ public static final int UPDATE_PAYTOOLTYPE_FAIL = -10; /** * 第三方订单号重复 */ public static final int THIRDPART_ORDERID_DUPLICATED = -31; /** * 支付工具通知的支付状态非法 */ public static final int PAYTOOL_PAY_STATUS_ERROR = -51; /** * 数据库异常 */ public static final int DDB_EXCEPTION = -101; /** * 代金券状态异常 */ public static final int VOUCHER_STATUS_EXCEPTION = -2001; /** * 支付停用 */ public static final int PAY_STOP = -1001; public static final Map<Integer, String> TIPS = new HashMap<Integer, String>(); static { TIPS.put(NORMAL_ERROR, "支付请求失败,请重试"); TIPS.put(YIXIN_ACCOUNTID_ERROR, "账号登录失败,请重试"); TIPS.put(GENERATE_SIGNATURE_FAIL, "生成签名失败,请重试"); TIPS.put(VERIFY_SIGNATURE_FAIL, "验证签名失败,请重试"); TIPS.put(GOODS_NOT_EXIST, "商品不存在,请重试"); TIPS.put(TRADE_NOT_EXIST, "订单不存在,请重试"); TIPS.put(PAYMETHOD_ERROR, "支付方式错误,请重试"); TIPS.put(PARAMETER_ILLEGAL, "参数非法"); TIPS.put(TIMEOUT_ERROR, "支付超时,请重新支付"); TIPS.put(THIRDPART_ORDERID_DUPLICATED, "订单重复"); TIPS.put(PAYTOOL_PAY_STATUS_ERROR, "无效订单"); TIPS.put(DDB_EXCEPTION, "支付数据请求失败,请重试"); TIPS.put(UPDATE_PAYTOOLTYPE_FAIL, "更新PayToolType失败"); TIPS.put(VOUCHER_STATUS_EXCEPTION, "您的代金券状态异常,请联系客服解决"); } /** * 构造函数 * * @param msg * 消息ID */ public PayException(int msg) { super(); this.msgId = msg; } /** * 构造函数 * * @param msg * 消息ID * @param cause * 父异常对象 */ public PayException(int msg, Throwable cause) { super(cause); this.msgId = msg; } /** * 构造函数 * * @param msg * 消息ID * @param content * 消息内容 */ public PayException(int msg, String content) { super(content); this.msgId = msg; } /** * 构造函数 * * @param msg * 消息ID * @param content * 消息内容 */ public PayException(int msg, String content, Throwable cause) { super(content, cause); this.msgId = msg; } public int getMsgId() { return msgId; } public void setMsgId(int msgId) { this.msgId = msgId; } }
以上是自己写Exception代码,如果我们写Logger的话,我们直接
private static final Logger logger = Logger.getLogger(PayController.class); private static final Logger payLogger = Logger.getLogger("PayLog");
logger.error("accessToken=" + accessToken); payLogger.error("accessToken=" + accessToken);