test-errcode
wangchuxiao 2 years ago
parent 23c2d81c2c
commit daffe8a7b7

@ -143,7 +143,14 @@ func (l *ZapLogger) Error(ctx context.Context, msg string, err error, keysAndVal
} }
func (l *ZapLogger) kvAppend(ctx context.Context, keysAndValues []interface{}) []interface{} { func (l *ZapLogger) kvAppend(ctx context.Context, keysAndValues []interface{}) []interface{} {
keysAndValues = append([]interface{}{constant.OperationID, tracelog.GetOperationID(ctx), constant.OpUserID, tracelog.GetOpUserID(ctx)}, keysAndValues...) operationID := tracelog.GetOperationID(ctx)
opUserID := tracelog.GetOpUserID(ctx)
if opUserID != "" {
keysAndValues = append([]interface{}{constant.OpUserID, tracelog.GetOpUserID(ctx)}, keysAndValues...)
}
if operationID != "" {
keysAndValues = append([]interface{}{constant.OperationID, tracelog.GetOperationID(ctx)}, keysAndValues...)
}
return keysAndValues return keysAndValues
} }

@ -1,6 +1,7 @@
package tracelog package tracelog
import ( import (
"OpenIM/pkg/common/constant"
"OpenIM/pkg/utils" "OpenIM/pkg/utils"
"context" "context"
"github.com/sirupsen/logrus" "github.com/sirupsen/logrus"
@ -40,12 +41,17 @@ func GetOperationID(ctx context.Context) string {
return f.OperationID return f.OperationID
} }
} }
return utils.GetFuncName(3) return ""
} }
func GetOpUserID(ctx context.Context) string { func GetOpUserID(ctx context.Context) string {
s, _ := ctx.Value("opUserID").(string) if ctx.Value(constant.OpUserID) != "" {
return s s, ok := ctx.Value(constant.OpUserID).(string)
if ok {
return s
}
}
return ""
} }
func Unwrap(err error) error { func Unwrap(err error) error {

Loading…
Cancel
Save