From d6e1229961bf157fd3cee415c6f726b1de3ab186 Mon Sep 17 00:00:00 2001 From: Yun Date: Sun, 1 Mar 2026 22:28:59 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=E5=93=8D=E5=BA=94=E6=97=A5?= =?UTF-8?q?=E5=BF=97=E7=9A=84=E6=89=93=E5=8D=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- curlx.go | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/curlx.go b/curlx.go index 0633ed0..be29ce5 100644 --- a/curlx.go +++ b/curlx.go @@ -129,15 +129,22 @@ func (c *Curlx) Send(ctx context.Context, p ...Param) (res []byte, err error) { status := resp.GetStatusCode() if status != 200 { + c.opts.Logger.Errorf(ctx, "curlx.Send status not OK: %d", status) return nil, ErrStatusNotOK } body, err := resp.GetBody() if err != nil { + c.opts.Logger.Errorf(ctx, "curlx.Send getBody err:%v", err) return nil, err } - c.opts.Logger.Infof(ctx, "curlx.Send body:%s", string(body)) + // 打印日志时截取前指定长度,避免日志过大 + bodyLog := []rune(string(body)) + if len(bodyLog) > c.opts.LoggerLength { + bodyLog = bodyLog[:c.opts.LoggerLength] + } + c.opts.Logger.Infof(ctx, "curlx.Send response body:%s", string(bodyLog)) return body, nil }