diff --git a/httpclient/client.go b/httpclient/client.go index 0392a84..e04364f 100644 --- a/httpclient/client.go +++ b/httpclient/client.go @@ -106,11 +106,11 @@ func NewHttpClient(reqConfig *define.Request, cacheInstance cache.ICache) (*Http hc.OnRequestFinish(func(req *define.Request, rep *define.Response) { if rep.IsSuccess { // 请求成功 - log.Record(req.Ctx, req.Logger, consts.LogLevelInfo, "接口请求成功", req, rep) + log.Record(consts.LogLevelInfo, "接口请求成功", req, rep) return } // 请求失败 - log.Record(req.Ctx, req.Logger, consts.LogLevelError, "接口请求失败", req, rep) + log.Record(consts.LogLevelError, "接口请求失败", req, rep) }) return hc, nil } @@ -292,6 +292,8 @@ func (hc *HttpClient) Request() *define.Response { _ = hc.requestBackendApi() }() }() + // 命中缓存必然请求成功, 直接记录成功日志即可 + log.Record(consts.LogLevelInfo, "接口请求成功:命中缓存", hc.reqConfig, cacheResult) return cacheResult } diff --git a/httpclient/log/log.go b/httpclient/log/log.go index e2d4dba..56b2867 100644 --- a/httpclient/log/log.go +++ b/httpclient/log/log.go @@ -58,8 +58,8 @@ func GetBuildDataFunc() BuildHttpLogDataFunc { // Author : go_developer@163.com<白茶清欢> // // Date : 18:07 2025/3/31 -func Record(ctx context.Context, logInstance *zap.Logger, level consts.LogLevel, msg string, reqCfg *define.Request, response *define.Response) { - if nil == logInstance { +func Record(level consts.LogLevel, msg string, reqCfg *define.Request, response *define.Response) { + if nil == reqCfg.Logger { // 未设置日志实例 return } @@ -68,7 +68,8 @@ func Record(ctx context.Context, logInstance *zap.Logger, level consts.LogLevel, // 未设置构建日志数据的方法 return } - fields := buildDataFunc(ctx, true, nil, reqCfg, response) + fields := buildDataFunc(reqCfg.Ctx, true, nil, reqCfg, response) + logInstance := reqCfg.Logger switch level { case consts.LogLevelDebug: logInstance.Debug(msg, fields...)