支持设置日志实例

This commit is contained in:
2025-03-31 18:05:07 +08:00
parent 1d8ee18a03
commit 6a5aefafae
5 changed files with 148 additions and 1 deletions

View File

@ -27,6 +27,9 @@ import (
//
// Date : 15:27 2024/5/31
func NewHttpClient(reqConfig *define.Request, cacheInstance cache.ICache) (*HttpClient, error) {
if nil == reqConfig.Logger {
reqConfig.Logger = logger // 未单独指定日志实例, 则使用全局日志实例
}
// 验证配置正确性以及初始化默认值
if err := validate.RequestConfig(reqConfig); nil != err {
return nil, err

View File

@ -7,7 +7,10 @@
// Date : 2024-05-24 17:09
package define
import "context"
import (
"context"
"go.uber.org/zap"
)
// Request 请求配置
//
@ -33,6 +36,7 @@ type Request struct {
ConnectTimeout int64 `json:"connect_timeout"` // 连接超时时间: ms
ReadTimeout int64 `json:"read_timeout"` // 读取超时时间
RetryRule *RequestRetryRule `json:"retry_rule"` // 重试规则
Logger *zap.Logger `json:"-"` // 日志记录器
}
// RequestRetryRule 重试规则

23
httpclient/log.go Normal file
View File

@ -0,0 +1,23 @@
// Package httpclient ...
//
// Description : httpclient ...
//
// Author : go_developer@163.com<白茶清欢>
//
// Date : 2025-03-31 18:02
package httpclient
import "go.uber.org/zap"
var (
logger *zap.Logger
)
// SetLogger 设置日志实例
//
// Author : go_developer@163.com<白茶清欢>
//
// Date : 18:02 2025/3/31
func SetLogger(l *zap.Logger) {
logger = l
}