feat: AGV状态实时推送与受控异常处置 + rcs-dps状态接口独立配置与日志落盘修复
This commit is contained in:
@@ -12,9 +12,13 @@ import (
|
||||
"io"
|
||||
"net/http"
|
||||
|
||||
"bj_power_wms/internal/netutil"
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
)
|
||||
|
||||
// commTag 本机 IP 前缀(进程启动解析一次),断网排查时可一眼看出日志来自哪台机器。
|
||||
var commTag = netutil.Tag()
|
||||
|
||||
// loggingTransport 日志装饰 transport。
|
||||
type loggingTransport struct{ base http.RoundTripper }
|
||||
|
||||
@@ -35,11 +39,11 @@ func (t *loggingTransport) RoundTrip(req *http.Request) (*http.Response, error)
|
||||
_ = req.Body.Close()
|
||||
req.Body = io.NopCloser(bytes.NewReader(reqBody))
|
||||
}
|
||||
logx.WithContext(req.Context()).Infof("[WMS→MES] --> %s %s body=%s", req.Method, u, truncateLogBytes(reqBody))
|
||||
logx.WithContext(req.Context()).Infof("[WMS→MES]"+commTag+" --> %s %s body=%s", req.Method, u, truncateLogBytes(reqBody))
|
||||
|
||||
resp, err := t.base.RoundTrip(req)
|
||||
if err != nil {
|
||||
logx.WithContext(req.Context()).Errorf("[WMS→MES] <-- transport error %s err=%v", u, err)
|
||||
logx.WithContext(req.Context()).Errorf("[WMS→MES]"+commTag+" <-- transport error %s err=%v", u, err)
|
||||
if FailHook != nil {
|
||||
FailHook(req.Context(), req.Method, u, err)
|
||||
}
|
||||
@@ -48,10 +52,10 @@ func (t *loggingTransport) RoundTrip(req *http.Request) (*http.Response, error)
|
||||
raw, rerr := io.ReadAll(resp.Body)
|
||||
_ = resp.Body.Close()
|
||||
if rerr != nil {
|
||||
logx.WithContext(req.Context()).Errorf("[WMS→MES] <-- read body error %s status=%d err=%v", u, resp.StatusCode, rerr)
|
||||
logx.WithContext(req.Context()).Errorf("[WMS→MES]"+commTag+" <-- read body error %s status=%d err=%v", u, resp.StatusCode, rerr)
|
||||
}
|
||||
resp.Body = io.NopCloser(bytes.NewReader(raw))
|
||||
logx.WithContext(req.Context()).Infof("[WMS→MES] <-- HTTP %d %s body=%s", resp.StatusCode, u, truncateLogBytes(raw))
|
||||
logx.WithContext(req.Context()).Infof("[WMS→MES]"+commTag+" <-- HTTP %d %s body=%s", resp.StatusCode, u, truncateLogBytes(raw))
|
||||
return resp, nil
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user