@@ -28,6 +28,8 @@ func init() {
2828 log = log .Named (Name )
2929 return func (next service.HandlerFunc ) service.HandlerFunc {
3030 return func (ctx context.Context , req service.Request , resp service.Response ) error {
31+ now := time .Now ()
32+
3133 // TODO 考虑pool优化
3234 var params = make ([]zap.Field , 0 , 20 )
3335
@@ -39,7 +41,6 @@ func init() {
3941 var reqId = requestid .GetReqId (ctx )
4042 var tracerID , spanID = tracing .GetFrom (ctx ).SpanID ()
4143
42- now := time .Now ()
4344 params = append (params , zap .String ("requestId" , reqId ))
4445 params = append (params , zap .String ("tracerId" , tracerID ))
4546 params = append (params , zap .String ("spanId" , spanID ))
@@ -50,8 +51,6 @@ func init() {
5051 params = append (params , zap .Bool ("client" , req .Client ()))
5152 params = append (params , zap .String ("version" , version .Version ))
5253
53- var respBody interface {}
54- var respHeader interface {}
5554 var err error
5655
5756 // 错误和panic处理
@@ -73,13 +72,13 @@ func init() {
7372 }
7473
7574 // TODO type assert
76- params = append (params , zap .String ("req_body" , fmt .Sprintf ("%s " , req .Payload ())))
77- params = append (params , zap .Any ("resp_body " , fmt .Sprintf ("%s " , respBody )))
75+ params = append (params , zap .String ("req_body" , fmt .Sprintf ("%v " , req .Payload ())))
76+ params = append (params , zap .Any ("rsp_body " , fmt .Sprintf ("%v " , resp . Payload () )))
7877 params = append (params , zap .Any ("req_header" , req .Header ()))
79- params = append (params , zap .Any ("resp_header " , respHeader ))
78+ params = append (params , zap .Any ("rsp_header " , resp . Header () ))
8079
8180 // 持续时间, 微秒
82- params = append (params , zap .Int64 ("duration" , time .Since (now ).Microseconds ()))
81+ params = append (params , zap .String ("duration" , time .Since (now ).String ()))
8382 // 记录错误日志
8483 logutil .LogOrErr (log , req .Endpoint (), func () error { return err }, params ... )
8584 }()
0 commit comments