提交 760a48d8 authored 作者: 张立波's avatar 张立波

log Async

上级 25807edd
......@@ -86,9 +86,9 @@ func (s *Config) Post(ctx context.Context, method string, params g.Map) (str str
ctx = context.WithValue(ctx, "Method", "POST")
ctx = context.WithValue(ctx, "URI", Url)
if err != nil {
g.Log().Ctx(ctx).Cat(PkgName).Cat("error").Infof("参数【%v】错误【%v】响应时间【%v】", paramStr, err.Error(), gtime.TimestampMilli()-Start)
g.Log().Async(true).Ctx(ctx).Cat(PkgName).Cat("error").Infof("参数【%v】错误【%v】响应时间【%v】", paramStr, err.Error(), gtime.TimestampMilli()-Start)
} else {
g.Log().Ctx(ctx).Cat(PkgName).Infof("参数【%v】响应【%v】响应时间【%v】", paramStr, str, gtime.TimestampMilli()-Start)
g.Log().Async(true).Ctx(ctx).Cat(PkgName).Infof("参数【%v】响应【%v】响应时间【%v】", paramStr, str, gtime.TimestampMilli()-Start)
}
}()
str = resp.ReadAllString()
......
......@@ -86,9 +86,9 @@ func (s *Config) Post(ctx context.Context, method string, params g.Map) (str str
ctx = context.WithValue(ctx, "Method", "POST")
ctx = context.WithValue(ctx, "URI", Url)
if err != nil {
g.Log().Cat(PkgName).Ctx(ctx).Infof("参数【%v】错误【%v】响应时间【%v】", paramStr, err.Error(), gtime.TimestampMilli()-Start)
g.Log().Async(true).Cat(PkgName).Ctx(ctx).Infof("参数【%v】错误【%v】响应时间【%v】", paramStr, err.Error(), gtime.TimestampMilli()-Start)
} else {
g.Log().Cat(PkgName).Ctx(ctx).Infof("参数【%v】响应【%v】响应时间【%v】", paramStr,str, gtime.TimestampMilli()-Start)
g.Log().Async(true).Cat(PkgName).Ctx(ctx).Infof("参数【%v】响应【%v】响应时间【%v】", paramStr, str, gtime.TimestampMilli()-Start)
}
}()
str = resp.ReadAllString()
......
......@@ -86,9 +86,9 @@ func (s *Config) Post(ctx context.Context, method string, params g.Map) (str str
ctx = context.WithValue(ctx, "Method", "POST")
ctx = context.WithValue(ctx, "URI", Url)
if err != nil {
g.Log().Cat(PkgName).Ctx(ctx).Infof("参数【%v】错误【%v】响应时间【%v】", paramStr, err.Error(), gtime.TimestampMilli()-Start)
g.Log().Async(true).Cat(PkgName).Ctx(ctx).Infof("参数【%v】错误【%v】响应时间【%v】", paramStr, err.Error(), gtime.TimestampMilli()-Start)
} else {
g.Log().Cat(PkgName).Ctx(ctx).Infof("参数【%v】响应【%v】响应时间【%v】", paramStr,str, gtime.TimestampMilli()-Start)
g.Log().Async(true).Cat(PkgName).Ctx(ctx).Infof("参数【%v】响应【%v】响应时间【%v】", paramStr, str, gtime.TimestampMilli()-Start)
}
}()
str = resp.ReadAllString()
......
......@@ -93,9 +93,9 @@ func post(ctx context.Context, method string, req interface{}) (res *CommonRes,
ctx = context.WithValue(ctx, "Method", "POST")
ctx = context.WithValue(ctx, "URI", method)
if err != nil {
g.Log().Ctx(ctx).Cat(PkgName).Cat("error").Infof("参数【%v】错误【%v】响应时间【%v】", request.MustToJsonString(), err.Error(), gtime.TimestampMilli()-Start)
g.Log().Async(true).Ctx(ctx).Cat(PkgName).Cat("error").Infof("参数【%v】错误【%v】响应时间【%v】", request.MustToJsonString(), err.Error(), gtime.TimestampMilli()-Start)
} else {
g.Log().Ctx(ctx).Cat(PkgName).Infof("参数【%v】响应【%v】响应时间【%v】", request.MustToJsonString(), str, gtime.TimestampMilli()-Start)
g.Log().Async(true).Ctx(ctx).Cat(PkgName).Infof("参数【%v】响应【%v】响应时间【%v】", request.MustToJsonString(), str, gtime.TimestampMilli()-Start)
}
}()
str = resp.ReadAllString()
......
......@@ -48,16 +48,16 @@ func post(ctx context.Context, method string, req interface{}) (res string, err
ctx = context.WithValue(ctx, "Method", "POST")
ctx = context.WithValue(ctx, "URI", Url)
if err != nil {
g.Log().Ctx(ctx).Cat(pkgName).Cat("error").Infof("参数【%v】错误【%v】响应时间【%v】", param.MustToJsonString(), err.Error(), gtime.TimestampMilli()-Start)
g.Log().Async(true).Ctx(ctx).Cat(pkgName).Cat("error").Infof("参数【%v】错误【%v】响应时间【%v】", param.MustToJsonString(), err.Error(), gtime.TimestampMilli()-Start)
} else {
g.Log().Ctx(ctx).Cat(pkgName).Infof("参数【%v】响应【%v】响应时间【%v】", param.MustToJsonString(), res, gtime.TimestampMilli()-Start)
g.Log().Async(true).Ctx(ctx).Cat(pkgName).Infof("参数【%v】响应【%v】响应时间【%v】", param.MustToJsonString(), res, gtime.TimestampMilli()-Start)
}
}()
res = resp.ReadAllString()
return
}
//检测回调sign
// 检测回调sign
func CheckSign(r *ghttp.Request) (body string, err error) {
signStr := gconv.String(r.GetHeader("sign"))
body = r.GetBodyString()
......
......@@ -49,9 +49,9 @@ func post(ctx context.Context, method string, req interface{}) (res string, err
ctx = context.WithValue(ctx, "Method", "POST")
ctx = context.WithValue(ctx, "URI", method)
if err != nil {
g.Log().Ctx(ctx).Infof("参数【%v】错误【%v】响应时间【%v】", param.MustToJsonString(), err.Error(), gtime.TimestampMilli()-Start)
g.Log().Async(true).Ctx(ctx).Infof("参数【%v】错误【%v】响应时间【%v】", param.MustToJsonString(), err.Error(), gtime.TimestampMilli()-Start)
} else {
g.Log().Ctx(ctx).Cat(pkgName).Infof("参数【%v】响应【%v】响应时间【%v】", param.MustToJsonString(), res, gtime.TimestampMilli()-Start)
g.Log().Async(true).Ctx(ctx).Cat(pkgName).Infof("参数【%v】响应【%v】响应时间【%v】", param.MustToJsonString(), res, gtime.TimestampMilli()-Start)
}
}()
res = resp.ReadAllString()
......
......@@ -52,7 +52,7 @@ func New(config *Config) {
return
}
//post 请求
// post 请求
func (s *client) post(ctx context.Context, method string, params g.Map) (str string, err error) {
Start := gtime.TimestampMilli()
Request := g.Client()
......@@ -64,9 +64,9 @@ func (s *client) post(ctx context.Context, method string, params g.Map) (str str
ctx = context.WithValue(ctx, "Method", "POST")
ctx = context.WithValue(ctx, "URI", method)
if err != nil {
g.Log().Ctx(ctx).Cat(pkgName).Cat("error").Infof("参数【%v】错误【%v】响应时间【%v ms】", paramStr, err.Error(), gtime.TimestampMilli()-Start)
g.Log().Async(true).Ctx(ctx).Cat(pkgName).Cat("error").Infof("参数【%v】错误【%v】响应时间【%v ms】", paramStr, err.Error(), gtime.TimestampMilli()-Start)
} else {
g.Log().Ctx(ctx).Cat(pkgName).Infof("参数【%v】响应【%v】响应时间【%v ms】", paramStr, str, gtime.TimestampMilli()-Start)
g.Log().Async(true).Ctx(ctx).Cat(pkgName).Infof("参数【%v】响应【%v】响应时间【%v ms】", paramStr, str, gtime.TimestampMilli()-Start)
}
}()
if err != nil {
......@@ -76,7 +76,7 @@ func (s *client) post(ctx context.Context, method string, params g.Map) (str str
return
}
//getSign 签名
// getSign 签名
func (s *client) getSign(timeStamp string) string {
var str = s.AppSecret + timeStamp + s.AppKey + s.UserName
return strings.ToUpper(gmd5.MustEncrypt(str + gmd5.MustEncrypt(s.PassWord) + "access_token" + s.AppSecret))
......
......@@ -57,10 +57,10 @@ func (s *Config) Post(ctx context.Context, URL string, bodyMap g.Map) (result st
defer func() {
ctx = context.WithValue(ctx, "URI", URL)
if err != nil {
g.Log().Ctx(ctx).Cat(pkgName).Cat("error").
g.Log().Ctx(ctx).Async(true).Cat(pkgName).Cat("error").
Infof("参数【%v】错误【%v】响应时间:【%v ms】", gjson.New(bodyMap).MustToJsonString(), err.Error(), gtime.TimestampMilli()-Start)
} else {
g.Log().Ctx(ctx).Cat(pkgName).
g.Log().Ctx(ctx).Async(true).Cat(pkgName).
Infof("参数【%v】响应【%v】响应时间:【%v ms】", gjson.New(bodyMap).MustToJsonString(), result, gtime.TimestampMilli()-Start)
}
}()
......
......@@ -110,9 +110,9 @@ func post(ctx context.Context, method string, params map[string]string) (str str
ctx = context.WithValue(ctx, "Method", "POST")
ctx = context.WithValue(ctx, "URI", apiUrl+params["Action"])
if err != nil {
g.Log().Ctx(ctx).Cat(PkgName).Cat("error").Infof("参数【%v】错误【%v】响应时间【%v】", paramStr, err.Error(), gtime.TimestampMilli()-Start)
g.Log().Ctx(ctx).Async(true).Cat(PkgName).Cat("error").Infof("参数【%v】错误【%v】响应时间【%v】", paramStr, err.Error(), gtime.TimestampMilli()-Start)
} else {
g.Log().Ctx(ctx).Cat(PkgName).Infof("参数【%v】响应【%v】响应时间【%v】", paramStr, str, gtime.TimestampMilli()-Start)
g.Log().Ctx(ctx).Async(true).Cat(PkgName).Infof("参数【%v】响应【%v】响应时间【%v】", paramStr, str, gtime.TimestampMilli()-Start)
}
}()
str = resp.ReadAllString()
......
......@@ -11,12 +11,12 @@ import (
)
type Config struct {
AppKey string
AppSecret string
TenantId string
DistributorId string
DistributionMallId string
DistributionSupplierId string
AppKey string
AppSecret string
TenantId string
DistributorId string
DistributionMallId string
DistributionSupplierId string
}
var server *Config
......@@ -33,17 +33,17 @@ const (
format string = "JSON"
typeAnony string = "ANONY"
typeEp string = "EP"
logName string = "tmNew"
logName string = "tmNew"
)
func New(req *Config) {
server = req
return
}
func initClient() (client *link.Client, err error){
config:=&openapi.Config{
AccessKeyId: tea.String(server.AppKey),
AccessKeySecret: tea.String(server.AppSecret),
func initClient() (client *link.Client, err error) {
config := &openapi.Config{
AccessKeyId: tea.String(server.AppKey),
AccessKeySecret: tea.String(server.AppSecret),
}
// 访问的域名
config.Endpoint = tea.String("linkedmall.aliyuncs.com")
......@@ -51,16 +51,17 @@ func initClient() (client *link.Client, err error){
client, err = link.NewClient(config)
return
}
func log(ctx context.Context,param string ,res interface{},err error){
func log(ctx context.Context, param string, res interface{}, err error) {
start := gtime.TimestampMilli()
resString ,_:=json.Marshal(res)
resString, _ := json.Marshal(res)
if err != nil {
g.Log().Ctx(ctx).Cat(logName).Cat("error").Infof("参数【%v】错误【%v】响应时间【%v】", param, err.Error(), gtime.TimestampMilli()-start)
g.Log().Ctx(ctx).Async(true).Cat(logName).Cat("error").Infof("参数【%v】错误【%v】响应时间【%v】", param, err.Error(), gtime.TimestampMilli()-start)
} else {
g.Log().Ctx(ctx).Cat(logName).Infof("参数【%v】响应【%v】响应时间【%v】", param, string(resString), gtime.TimestampMilli()-start)
g.Log().Ctx(ctx).Async(true).Cat(logName).Infof("参数【%v】响应【%v】响应时间【%v】", param, string(resString), gtime.TimestampMilli()-start)
}
return
}
// todo 部分接口验签通过,部分不通过天猫技术不支持对接,后续有时间再自己写
//func specialUrlEncode(req string) (res string) {
// req = url.QueryEscape(req)
......
......@@ -38,9 +38,9 @@ func New(req *Config) {
func Log(ctx context.Context, req interface{}, res interface{}, err error, start int64) {
if err != nil {
g.Log().Ctx(ctx).Cat(PkgName).Errorf("参数【%v】错误【%v】响应时间【%vms】", gjson.New(req).MustToJsonString(), err.Error(), gtime.TimestampMilli()-start)
g.Log().Ctx(ctx).Async(true).Cat(PkgName).Errorf("参数【%v】错误【%v】响应时间【%vms】", gjson.New(req).MustToJsonString(), err.Error(), gtime.TimestampMilli()-start)
} else {
g.Log().Ctx(ctx).Cat(PkgName).Infof("参数【%v】响应【%v】响应时间【%vms】", gjson.New(req).MustToJsonString(), gjson.New(res).MustToJsonString(), gtime.TimestampMilli()-start)
g.Log().Ctx(ctx).Async(true).Cat(PkgName).Infof("参数【%v】响应【%v】响应时间【%vms】", gjson.New(req).MustToJsonString(), gjson.New(res).MustToJsonString(), gtime.TimestampMilli()-start)
}
}
......
......@@ -95,9 +95,9 @@ func post(ctx context.Context, method string, req interface{}) (res string, err
ctx = context.WithValue(ctx, "Method", "POST")
ctx = context.WithValue(ctx, "URI", method)
if err != nil {
g.Log().Ctx(ctx).Cat(pkgName).Cat("error").Infof("参数【%v】错误【%v】响应时间【%v】", paramStr, err.Error(), gtime.TimestampMilli()-Start)
g.Log().Ctx(ctx).Async(true).Cat(pkgName).Cat("error").Infof("参数【%v】错误【%v】响应时间【%v】", paramStr, err.Error(), gtime.TimestampMilli()-Start)
} else {
g.Log().Ctx(ctx).Cat(pkgName).Infof("参数【%v】响应【%v】响应时间【%v】", paramStr, res, gtime.TimestampMilli()-Start)
g.Log().Ctx(ctx).Async(true).Cat(pkgName).Infof("参数【%v】响应【%v】响应时间【%v】", paramStr, res, gtime.TimestampMilli()-Start)
}
}()
res = resp.ReadAllString()
......
......@@ -119,9 +119,9 @@ func (s *Client) get(ctx context.Context, method string, params g.Map, xToken ..
ctx = context.WithValue(ctx, "Method", "GET")
ctx = context.WithValue(ctx, "URI", method)
if err != nil {
g.Log().Ctx(ctx).Cat(pkgName).Cat("error").Infof("参数【%v】错误【%v】响应时间【%v ms】", paramStr, err.Error(), gtime.TimestampMilli()-Start)
g.Log().Ctx(ctx).Async(true).Cat(pkgName).Cat("error").Infof("参数【%v】错误【%v】响应时间【%v ms】", paramStr, err.Error(), gtime.TimestampMilli()-Start)
} else {
g.Log().Ctx(ctx).Cat(pkgName).Infof("参数【%v】响应【%v】响应时间【%v ms】", paramStr, str, gtime.TimestampMilli()-Start)
g.Log().Ctx(ctx).Async(true).Cat(pkgName).Infof("参数【%v】响应【%v】响应时间【%v ms】", paramStr, str, gtime.TimestampMilli()-Start)
}
}()
if err != nil {
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论