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{} {
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
}

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

Loading…
Cancel
Save