httpclient支持mesh请求 #2
@ -1,4 +1,4 @@
|
|||||||
// Package httpclient ...
|
// Package log ...
|
||||||
//
|
//
|
||||||
// Description : httpclient ...
|
// Description : httpclient ...
|
||||||
//
|
//
|
||||||
@ -8,7 +8,9 @@
|
|||||||
package log
|
package log
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"context"
|
||||||
"git.zhangdeman.cn/zhangdeman/consts"
|
"git.zhangdeman.cn/zhangdeman/consts"
|
||||||
|
"git.zhangdeman.cn/zhangdeman/network/httpclient/define"
|
||||||
"go.uber.org/zap"
|
"go.uber.org/zap"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -34,16 +36,35 @@ func Get() *zap.Logger {
|
|||||||
return logger
|
return logger
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var buildHttpLogDataFunc BuildHttpLogDataFunc
|
||||||
|
|
||||||
|
// BuildHttpLogDataFunc 构建http请求日志数据的方法
|
||||||
|
type BuildHttpLogDataFunc func(ctx context.Context, reqCfg *define.Request, response *define.Response) []zap.Field
|
||||||
|
|
||||||
|
func SetBuildDataFunc(f BuildHttpLogDataFunc) {
|
||||||
|
buildHttpLogDataFunc = f
|
||||||
|
}
|
||||||
|
|
||||||
|
func GetBuildDataFunc() BuildHttpLogDataFunc {
|
||||||
|
return buildHttpLogDataFunc
|
||||||
|
}
|
||||||
|
|
||||||
// Record 日志记录
|
// Record 日志记录
|
||||||
//
|
//
|
||||||
// Author : go_developer@163.com<白茶清欢>
|
// Author : go_developer@163.com<白茶清欢>
|
||||||
//
|
//
|
||||||
// Date : 18:07 2025/3/31
|
// Date : 18:07 2025/3/31
|
||||||
func Record(logInstance *zap.Logger, level consts.LogLevel, msg string, fields ...zap.Field) {
|
func Record(ctx context.Context, logInstance *zap.Logger, level consts.LogLevel, msg string, reqCfg *define.Request, response *define.Response) {
|
||||||
if nil == logInstance {
|
if nil == logInstance {
|
||||||
// 未设置日志实例
|
// 未设置日志实例
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
buildDataFunc := GetBuildDataFunc()
|
||||||
|
if nil == buildDataFunc {
|
||||||
|
// 未设置构建日志数据的方法
|
||||||
|
return
|
||||||
|
}
|
||||||
|
fields := buildDataFunc(ctx, reqCfg, response)
|
||||||
switch level {
|
switch level {
|
||||||
case consts.LogLevelDebug:
|
case consts.LogLevelDebug:
|
||||||
logInstance.Debug(msg, fields...)
|
logInstance.Debug(msg, fields...)
|
||||||
@ -56,5 +77,4 @@ func Record(logInstance *zap.Logger, level consts.LogLevel, msg string, fields .
|
|||||||
case consts.LogLevelPanic:
|
case consts.LogLevelPanic:
|
||||||
logInstance.Panic(msg, fields...)
|
logInstance.Panic(msg, fields...)
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user