diff --git a/cmd/api/main.go b/cmd/api/main.go index e18430df4..4108c4138 100644 --- a/cmd/api/main.go +++ b/cmd/api/main.go @@ -6,6 +6,7 @@ import ( "OpenIM/pkg/common/config" "OpenIM/pkg/common/log" "OpenIM/pkg/common/mw" + "context" "fmt" "github.com/OpenIMSDK/openKeeper" "os" @@ -40,7 +41,7 @@ func run(port int) error { address = config.Config.Api.ListenIP + ":" + strconv.Itoa(port) } fmt.Println("start api server, address: ", address, ", OpenIM version: ", config.Version) - //log2.Info(context.Background(), "start server success", "address", address, "version", config.Version) + log.ZInfo(context.Background(), "start server success", "address", address, "version", config.Version) log.Info("s", "start server") err = router.Run(address) if err != nil { diff --git a/cmd/push/main.go b/cmd/push/main.go index a89a3c111..cbe68d616 100644 --- a/cmd/push/main.go +++ b/cmd/push/main.go @@ -9,7 +9,7 @@ import ( ) func main() { - pushCmd := cmd.NewRpcCmd() + pushCmd := cmd.NewRpcCmd("push") pushCmd.AddPortFlag() pushCmd.AddPrometheusPortFlag() if err := pushCmd.Exec(); err != nil { diff --git a/cmd/rpc/auth/main.go b/cmd/rpc/auth/main.go index f1417366f..99e8f5128 100644 --- a/cmd/rpc/auth/main.go +++ b/cmd/rpc/auth/main.go @@ -9,7 +9,7 @@ import ( ) func main() { - authCmd := cmd.NewRpcCmd() + authCmd := cmd.NewRpcCmd("auth") authCmd.AddPortFlag() authCmd.AddPrometheusPortFlag() if err := authCmd.Exec(); err != nil { diff --git a/cmd/rpc/conversation/main.go b/cmd/rpc/conversation/main.go index aa81a8de1..087e6e4f8 100644 --- a/cmd/rpc/conversation/main.go +++ b/cmd/rpc/conversation/main.go @@ -9,7 +9,7 @@ import ( ) func main() { - rpcCmd := cmd.NewRpcCmd() + rpcCmd := cmd.NewRpcCmd("conversation") rpcCmd.AddPortFlag() rpcCmd.AddPrometheusPortFlag() if err := rpcCmd.Exec(); err != nil { diff --git a/cmd/rpc/friend/main.go b/cmd/rpc/friend/main.go index 7be637804..76384f6e5 100644 --- a/cmd/rpc/friend/main.go +++ b/cmd/rpc/friend/main.go @@ -9,7 +9,7 @@ import ( ) func main() { - rpcCmd := cmd.NewRpcCmd() + rpcCmd := cmd.NewRpcCmd("friend") rpcCmd.AddPortFlag() rpcCmd.AddPrometheusPortFlag() if err := rpcCmd.Exec(); err != nil { diff --git a/cmd/rpc/group/main.go b/cmd/rpc/group/main.go index 0a96d28d4..c1633e2fc 100644 --- a/cmd/rpc/group/main.go +++ b/cmd/rpc/group/main.go @@ -9,7 +9,7 @@ import ( ) func main() { - rpcCmd := cmd.NewRpcCmd() + rpcCmd := cmd.NewRpcCmd("group") rpcCmd.AddPortFlag() rpcCmd.AddPrometheusPortFlag() if err := rpcCmd.Exec(); err != nil { diff --git a/cmd/rpc/msg/main.go b/cmd/rpc/msg/main.go index 84bc8178a..e88a8f528 100644 --- a/cmd/rpc/msg/main.go +++ b/cmd/rpc/msg/main.go @@ -9,7 +9,7 @@ import ( ) func main() { - rpcCmd := cmd.NewRpcCmd() + rpcCmd := cmd.NewRpcCmd("msg") rpcCmd.AddPortFlag() rpcCmd.AddPrometheusPortFlag() if err := rpcCmd.Exec(); err != nil { diff --git a/cmd/rpc/third/main.go b/cmd/rpc/third/main.go index 3360bbd14..060697561 100644 --- a/cmd/rpc/third/main.go +++ b/cmd/rpc/third/main.go @@ -9,7 +9,7 @@ import ( ) func main() { - rpcCmd := cmd.NewRpcCmd() + rpcCmd := cmd.NewRpcCmd("third") rpcCmd.AddPortFlag() rpcCmd.AddPrometheusPortFlag() if err := rpcCmd.Exec(); err != nil { diff --git a/cmd/rpc/user/main.go b/cmd/rpc/user/main.go index 6438280d1..b4b16685d 100644 --- a/cmd/rpc/user/main.go +++ b/cmd/rpc/user/main.go @@ -9,7 +9,7 @@ import ( ) func main() { - rpcCmd := cmd.NewRpcCmd() + rpcCmd := cmd.NewRpcCmd("user") rpcCmd.AddPortFlag() rpcCmd.AddPrometheusPortFlag() if err := rpcCmd.Exec(); err != nil { diff --git a/go.mod b/go.mod index d9b4bcdb6..f61180bf1 100644 --- a/go.mod +++ b/go.mod @@ -55,6 +55,7 @@ require ( github.com/jonboulle/clockwork v0.3.0 // indirect github.com/lestrrat-go/strftime v1.0.6 // indirect github.com/mattn/go-isatty v0.0.17 // indirect + github.com/natefinch/lumberjack v2.0.0+incompatible // indirect github.com/spf13/cobra v1.6.1 github.com/ugorji/go/codec v1.2.8 // indirect go.uber.org/zap v1.24.0 diff --git a/go.sum b/go.sum index 9f4ff7d28..79a467447 100644 --- a/go.sum +++ b/go.sum @@ -727,6 +727,8 @@ github.com/modern-go/reflect2 v1.0.2/go.mod h1:yWuevngMOJpCy52FWWMvUC8ws7m/LJsjY github.com/montanaflynn/stats v0.0.0-20171201202039-1bf9dbcd8cbe/go.mod h1:wL8QJuTMNUDYhXwkmfOly8iTdp5TEcJFWZD2D7SIkUc= github.com/mwitkow/go-conntrack v0.0.0-20161129095857-cc309e4a2223/go.mod h1:qRWi+5nqEBWmkhHvq77mSJWrCKwh8bxhgT7d/eI7P4U= github.com/mwitkow/go-conntrack v0.0.0-20190716064945-2f068394615f/go.mod h1:qRWi+5nqEBWmkhHvq77mSJWrCKwh8bxhgT7d/eI7P4U= +github.com/natefinch/lumberjack v2.0.0+incompatible h1:4QJd3OLAMgj7ph+yZTuX13Ld4UpgHp07nNdFX7mqFfM= +github.com/natefinch/lumberjack v2.0.0+incompatible/go.mod h1:Wi9p2TTF5DG5oU+6YfsmYQpsTIOm0B1VNzQg9Mw6nPk= github.com/nfnt/resize v0.0.0-20180221191011-83c6a9932646 h1:zYyBkD/k9seD2A7fsi6Oo2LfFZAehjjQMERAvZLEDnQ= github.com/nfnt/resize v0.0.0-20180221191011-83c6a9932646/go.mod h1:jpp1/29i3P1S/RLdc7JQKbRpFeM1dOBd8T9ki5s+AY8= github.com/nxadm/tail v1.4.4/go.mod h1:kenIhsEOeOJmVchQTgglprH7qJGnHDVpk1VPCcaMI8A= diff --git a/pkg/common/cmd/api.go b/pkg/common/cmd/api.go index f731953c3..22534c39d 100644 --- a/pkg/common/cmd/api.go +++ b/pkg/common/cmd/api.go @@ -7,7 +7,7 @@ type ApiCmd struct { } func NewApiCmd() *ApiCmd { - return &ApiCmd{NewRootCmd()} + return &ApiCmd{NewRootCmd("api")} } func (a *ApiCmd) AddApi(f func(port int) error) { diff --git a/pkg/common/cmd/cron_task.go b/pkg/common/cmd/cron_task.go index e12932a33..7795e5e3d 100644 --- a/pkg/common/cmd/cron_task.go +++ b/pkg/common/cmd/cron_task.go @@ -7,7 +7,7 @@ type CronTaskCmd struct { } func NewCronTaskCmd() *CronTaskCmd { - return &CronTaskCmd{NewRootCmd()} + return &CronTaskCmd{NewRootCmd("cronTask")} } func (c *CronTaskCmd) addRunE(f func() error) { diff --git a/pkg/common/cmd/msg_gateway.go b/pkg/common/cmd/msg_gateway.go index 489d12485..d0e662a70 100644 --- a/pkg/common/cmd/msg_gateway.go +++ b/pkg/common/cmd/msg_gateway.go @@ -12,7 +12,7 @@ type MsgGatewayCmd struct { } func NewMsgGatewayCmd() MsgGatewayCmd { - return MsgGatewayCmd{NewRootCmd()} + return MsgGatewayCmd{NewRootCmd("msgGateway")} } func (m *MsgGatewayCmd) AddWsPortFlag() { diff --git a/pkg/common/cmd/msg_transfer.go b/pkg/common/cmd/msg_transfer.go index 03a36fa87..544d7a48b 100644 --- a/pkg/common/cmd/msg_transfer.go +++ b/pkg/common/cmd/msg_transfer.go @@ -10,7 +10,7 @@ type MsgTransferCmd struct { } func NewMsgTransferCmd() MsgTransferCmd { - return MsgTransferCmd{NewRootCmd()} + return MsgTransferCmd{NewRootCmd("msgTransfer")} } func (m *MsgTransferCmd) addRunE() { diff --git a/pkg/common/cmd/msg_utils.go b/pkg/common/cmd/msg_utils.go index e1ea27185..424005004 100644 --- a/pkg/common/cmd/msg_utils.go +++ b/pkg/common/cmd/msg_utils.go @@ -18,7 +18,7 @@ type MsgUtilsCmd struct { } func NewMsgUtilsCmd() MsgUtilsCmd { - return MsgUtilsCmd{RootCmd: NewRootCmd()} + return MsgUtilsCmd{RootCmd: NewRootCmd("msgUtils")} } func (m *MsgUtilsCmd) AddUserIDFlag() { diff --git a/pkg/common/cmd/root.go b/pkg/common/cmd/root.go index 72a490ee2..833d2b06a 100644 --- a/pkg/common/cmd/root.go +++ b/pkg/common/cmd/root.go @@ -3,23 +3,29 @@ package cmd import ( "OpenIM/pkg/common/config" "OpenIM/pkg/common/constant" + "OpenIM/pkg/common/log" + "fmt" "github.com/spf13/cobra" ) type RootCmd struct { Command cobra.Command + Name string port int prometheusPort int } -func NewRootCmd() (rootCmd *RootCmd) { - rootCmd = &RootCmd{} +func NewRootCmd(name string) (rootCmd *RootCmd) { + rootCmd = &RootCmd{Name: name} c := cobra.Command{ Use: "start", - Short: "Start the server", - Long: `Start the server`, + Short: fmt.Sprintf(`Start %s server`, name), + Long: fmt.Sprintf(`Start %s server`, name), PersistentPreRunE: func(cmd *cobra.Command, args []string) error { - return rootCmd.getConfFromCmdAndInit(cmd) + if err := rootCmd.getConfFromCmdAndInit(cmd); err != nil { + return err + } + return log.InitFromConfig(name) }, } rootCmd.Command = c @@ -27,12 +33,6 @@ func NewRootCmd() (rootCmd *RootCmd) { return rootCmd } -func (r *RootCmd) SetDesc(use, short, long string) { - r.Command.Use = use - r.Command.Short = short - r.Command.Long = long -} - func (r *RootCmd) addConfFlag() { r.Command.Flags().StringP(constant.FlagConf, "c", "", "Path to config file folder") } diff --git a/pkg/common/cmd/rpc.go b/pkg/common/cmd/rpc.go index a5a4e80c7..e765436ee 100644 --- a/pkg/common/cmd/rpc.go +++ b/pkg/common/cmd/rpc.go @@ -11,8 +11,8 @@ type RpcCmd struct { *RootCmd } -func NewRpcCmd() *RpcCmd { - authCmd := &RpcCmd{NewRootCmd()} +func NewRpcCmd(name string) *RpcCmd { + authCmd := &RpcCmd{NewRootCmd(name)} return authCmd } diff --git a/pkg/common/log/lfs_hk.go b/pkg/common/log/lfs_hk.go new file mode 100644 index 000000000..4e65ddb94 --- /dev/null +++ b/pkg/common/log/lfs_hk.go @@ -0,0 +1,39 @@ +package log + +import ( + "OpenIM/pkg/common/config" + nested "github.com/antonfisher/nested-logrus-formatter" + rotatelogs "github.com/lestrrat-go/file-rotatelogs" + "github.com/rifflock/lfshook" + "github.com/sirupsen/logrus" + "time" +) + +func NewLfsHook(rotationTime time.Duration, maxRemainNum uint, moduleName string) logrus.Hook { + lfsHook := lfshook.NewHook(lfshook.WriterMap{ + logrus.DebugLevel: initRotateLogs(rotationTime, maxRemainNum, "all", moduleName), + logrus.InfoLevel: initRotateLogs(rotationTime, maxRemainNum, "all", moduleName), + logrus.WarnLevel: initRotateLogs(rotationTime, maxRemainNum, "all", moduleName), + logrus.ErrorLevel: initRotateLogs(rotationTime, maxRemainNum, "all", moduleName), + }, &nested.Formatter{ + TimestampFormat: "2006-01-02 15:04:05.000", + HideKeys: false, + FieldsOrder: []string{"PID", "FilePath", "OperationID", "Msg"}, + }) + return lfsHook +} +func initRotateLogs(rotationTime time.Duration, maxRemainNum uint, level string, moduleName string) *rotatelogs.RotateLogs { + if moduleName != "" { + moduleName = moduleName + "." + } + writer, err := rotatelogs.New( + config.Config.Log.StorageLocation+moduleName+level+"."+"%Y-%m-%d", + rotatelogs.WithRotationTime(rotationTime), + rotatelogs.WithRotationCount(maxRemainNum), + ) + if err != nil { + panic(err.Error()) + } else { + return writer + } +} diff --git a/pkg/common/log/logger.go b/pkg/common/log/logger.go index a2a637b6e..221c0ded5 100644 --- a/pkg/common/log/logger.go +++ b/pkg/common/log/logger.go @@ -7,7 +7,7 @@ type Logger interface { Info(ctx context.Context, msg string, keysAndValues ...interface{}) Warn(ctx context.Context, msg string, err error, keysAndValues ...interface{}) Error(ctx context.Context, msg string, err error, keysAndValues ...interface{}) - WithValues(keysAndValues ...interface{}) LogrusLogger - WithName(name string) LogrusLogger - WithCallDepth(depth int) LogrusLogger + WithValues(keysAndValues ...interface{}) Logger + WithName(name string) Logger + WithCallDepth(depth int) Logger } diff --git a/pkg/common/log/logrus.go b/pkg/common/log/logrus.go index 19d3c3c49..cdf783e1a 100644 --- a/pkg/common/log/logrus.go +++ b/pkg/common/log/logrus.go @@ -2,15 +2,16 @@ package log import ( "OpenIM/pkg/common/config" + "OpenIM/pkg/common/tracelog" "bufio" + "context" + //"bufio" "fmt" "os" "time" nested "github.com/antonfisher/nested-logrus-formatter" - rotatelogs "github.com/lestrrat-go/file-rotatelogs" - "github.com/rifflock/lfshook" "github.com/sirupsen/logrus" ) @@ -96,33 +97,26 @@ func loggerInit(moduleName string) *LogrusLogger { "", } } -func NewLfsHook(rotationTime time.Duration, maxRemainNum uint, moduleName string) logrus.Hook { - lfsHook := lfshook.NewHook(lfshook.WriterMap{ - logrus.DebugLevel: initRotateLogs(rotationTime, maxRemainNum, "all", moduleName), - logrus.InfoLevel: initRotateLogs(rotationTime, maxRemainNum, "all", moduleName), - logrus.WarnLevel: initRotateLogs(rotationTime, maxRemainNum, "all", moduleName), - logrus.ErrorLevel: initRotateLogs(rotationTime, maxRemainNum, "all", moduleName), - }, &nested.Formatter{ - TimestampFormat: "2006-01-02 15:04:05.000", - HideKeys: false, - FieldsOrder: []string{"PID", "FilePath", "OperationID"}, - }) - return lfsHook + +func InfoKv(ctx context.Context, msg string, keysAndValues ...interface{}) { + operationID := tracelog.GetOperationID(ctx) + logger.WithFields(logrus.Fields{ + "OperationID": operationID, + "PID": logger.Pid, + "Msg": msg, + }).Infoln(keysAndValues) } -func initRotateLogs(rotationTime time.Duration, maxRemainNum uint, level string, moduleName string) *rotatelogs.RotateLogs { - if moduleName != "" { - moduleName = moduleName + "." - } - writer, err := rotatelogs.New( - config.Config.Log.StorageLocation+moduleName+level+"."+"%Y-%m-%d", - rotatelogs.WithRotationTime(rotationTime), - rotatelogs.WithRotationCount(maxRemainNum), - ) - if err != nil { - panic(err.Error()) - } else { - return writer - } + +func DebugKv(ctx context.Context, msg string, keysAndValues ...interface{}) { + +} + +func ErrorKv(ctx context.Context, msg string, err error, keysAndValues ...interface{}) { + +} + +func WarnKv(ctx context.Context, msg string, err error, keysAndValues ...interface{}) { + } func Info(OperationID string, args ...interface{}) { diff --git a/pkg/common/logger/log.go b/pkg/common/log/zap.go similarity index 54% rename from pkg/common/logger/log.go rename to pkg/common/log/zap.go index d9f6fb974..2b51cb015 100644 --- a/pkg/common/logger/log.go +++ b/pkg/common/log/zap.go @@ -1,9 +1,12 @@ package log import ( + "OpenIM/pkg/common/config" "OpenIM/pkg/common/constant" "OpenIM/pkg/common/tracelog" "context" + rotatelogs "github.com/lestrrat-go/file-rotatelogs" + "path/filepath" "time" "go.uber.org/zap" @@ -12,6 +15,7 @@ import ( var ( pkgLogger Logger = &ZapLogger{} + sp = string(filepath.Separator) ) // InitFromConfig initializes a Zap-based logger @@ -24,39 +28,25 @@ func InitFromConfig(name string) error { return nil } -func Debug(ctx context.Context, msg string, keysAndValues ...interface{}) { +func ZDebug(ctx context.Context, msg string, keysAndValues ...interface{}) { pkgLogger.Debug(ctx, msg, keysAndValues...) } -func Info(ctx context.Context, msg string, keysAndValues ...interface{}) { +func ZInfo(ctx context.Context, msg string, keysAndValues ...interface{}) { pkgLogger.Info(ctx, msg, keysAndValues...) } -func Warn(ctx context.Context, msg string, err error, keysAndValues ...interface{}) { +func ZWarn(ctx context.Context, msg string, err error, keysAndValues ...interface{}) { pkgLogger.Warn(ctx, msg, err, keysAndValues...) } -func Error(ctx context.Context, msg string, err error, keysAndValues ...interface{}) { +func ZError(ctx context.Context, msg string, err error, keysAndValues ...interface{}) { pkgLogger.Error(ctx, msg, err, keysAndValues...) } -type Logger interface { - Debug(ctx context.Context, msg string, keysAndValues ...interface{}) - Info(ctx context.Context, msg string, keysAndValues ...interface{}) - Warn(ctx context.Context, msg string, err error, keysAndValues ...interface{}) - Error(ctx context.Context, msg string, err error, keysAndValues ...interface{}) - WithValues(keysAndValues ...interface{}) Logger - WithName(name string) Logger - WithCallDepth(depth int) Logger - WithItemSampler() Logger - // WithoutSampler returns the original logger without sampling - WithoutSampler() Logger -} - type ZapLogger struct { zap *zap.SugaredLogger // store original logger without sampling to avoid multiple samplers - unsampled *zap.SugaredLogger SampleDuration time.Duration SampleInitial int SampleInterval int @@ -64,29 +54,50 @@ type ZapLogger struct { func NewZapLogger() (*ZapLogger, error) { zapConfig := zap.Config{ - Level: zap.NewAtomicLevelAt(zapcore.DebugLevel), - Development: true, - Encoding: "json", - EncoderConfig: zap.NewProductionEncoderConfig(), - OutputPaths: []string{"stdout"}, - ErrorOutputPaths: []string{"stdout"}, - Sampling: &zap.SamplingConfig{ - Initial: 0, - Thereafter: 0, - Hook: nil, - }, + Level: zap.NewAtomicLevelAt(zapcore.DebugLevel), + Development: true, + Encoding: "json", + EncoderConfig: zap.NewProductionEncoderConfig(), } - l, err := zapConfig.Build() + zl := &ZapLogger{} + if config.Config.Log.Stderr { + zapConfig.OutputPaths = append(zapConfig.OutputPaths, "stderr") + } + l, err := zapConfig.Build(zl.cores()) if err != nil { return nil, err } - zl := &ZapLogger{ - unsampled: l.Sugar(), - } - + zl.zap = l.Sugar() return zl, nil } +func timeEncoder(t time.Time, enc zapcore.PrimitiveArrayEncoder) { + enc.AppendString(t.Format("2006-01-02 15:04:05")) +} + +func (l *ZapLogger) cores() zap.Option { + fileEncoder := zapcore.NewJSONEncoder(zap.NewProductionEncoderConfig()) + writer := l.getWriter() + var cores []zapcore.Core + if config.Config.Log.StorageLocation != "" { + cores = []zapcore.Core{ + zapcore.NewCore(fileEncoder, writer, zapcore.DebugLevel), + } + } + return zap.WrapCore(func(c zapcore.Core) zapcore.Core { + return zapcore.NewTee(cores...) + }) +} + +func (l *ZapLogger) getWriter() zapcore.WriteSyncer { + logf, _ := rotatelogs.New(config.Config.Log.StorageLocation+sp+"openIM"+"-"+".%Y_%m%d_%H", + rotatelogs.WithLinkName(config.Config.Log.StorageLocation+sp+"openIM"+"-"), + rotatelogs.WithMaxAge(2*24*time.Hour), + rotatelogs.WithRotationTime(time.Minute), + ) + return zapcore.AddSync(logf) +} + func (l *ZapLogger) ToZap() *zap.SugaredLogger { return l.zap } @@ -120,57 +131,17 @@ func (l *ZapLogger) Error(ctx context.Context, msg string, err error, keysAndVal func (l *ZapLogger) WithValues(keysAndValues ...interface{}) Logger { dup := *l dup.zap = l.zap.With(keysAndValues...) - if l.unsampled == l.zap { - dup.unsampled = dup.zap - } else { - dup.unsampled = l.unsampled.With(keysAndValues...) - } return &dup } func (l *ZapLogger) WithName(name string) Logger { dup := *l dup.zap = l.zap.Named(name) - if l.unsampled == l.zap { - dup.unsampled = dup.zap - } else { - dup.unsampled = l.unsampled.Named(name) - } return &dup } func (l *ZapLogger) WithCallDepth(depth int) Logger { dup := *l dup.zap = l.zap.WithOptions(zap.AddCallerSkip(depth)) - if l.unsampled == l.zap { - dup.unsampled = dup.zap - } else { - dup.unsampled = l.unsampled.WithOptions(zap.AddCallerSkip(depth)) - } - return &dup -} - -func (l *ZapLogger) WithItemSampler() Logger { - if l.SampleDuration == 0 { - return l - } - dup := *l - dup.zap = l.unsampled.WithOptions(zap.WrapCore(func(core zapcore.Core) zapcore.Core { - return zapcore.NewSamplerWithOptions( - core, - l.SampleDuration, - l.SampleInitial, - l.SampleInterval, - ) - })) - return &dup -} - -func (l *ZapLogger) WithoutSampler() Logger { - if l.SampleDuration == 0 { - return l - } - dup := *l - dup.zap = l.unsampled return &dup } diff --git a/pkg/common/logger/config.go b/pkg/common/logger/config.go deleted file mode 100644 index 58d1385d8..000000000 --- a/pkg/common/logger/config.go +++ /dev/null @@ -1,10 +0,0 @@ -package log - -var logMap = map[int]int{ - 6: -1, - 5: 0, - 4: 1, - 3: 2, - 2: 3, - 1: 4, -} diff --git a/pkg/common/tracelog/ctx.go b/pkg/common/tracelog/ctx.go index ed47678de..45df46d3f 100644 --- a/pkg/common/tracelog/ctx.go +++ b/pkg/common/tracelog/ctx.go @@ -34,11 +34,13 @@ func SetOperationID(ctx context.Context, operationID string) { } func GetOperationID(ctx context.Context) string { - f, ok := ctx.Value(TraceLogKey).(*FuncInfos) - if ok { - return f.OperationID + if ctx.Value(TraceLogKey) != nil { + f, ok := ctx.Value(TraceLogKey).(*FuncInfos) + if ok { + return f.OperationID + } } - return utils.GetFuncName(1) + return utils.GetFuncName(2) } func GetOpUserID(ctx context.Context) string {