mirror of
https://github.com/openimsdk/open-im-server.git
synced 2026-05-09 11:35:59 +08:00
Merge remote-tracking branch 'origin/errcode' into errcode
This commit is contained in:
+14
-5
@@ -65,9 +65,6 @@ func NewZapLogger() (*ZapLogger, error) {
|
||||
if config.Config.Log.Stderr {
|
||||
zapConfig.OutputPaths = append(zapConfig.OutputPaths, "stderr")
|
||||
}
|
||||
zapConfig.EncoderConfig.EncodeTime = zapcore.ISO8601TimeEncoder
|
||||
zapConfig.EncoderConfig.EncodeDuration = zapcore.SecondsDurationEncoder
|
||||
zapConfig.EncoderConfig.EncodeLevel = zapcore.CapitalColorLevelEncoder
|
||||
opts, err := zl.cores()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@@ -85,7 +82,12 @@ func (l *ZapLogger) timeEncoder(t time.Time, enc zapcore.PrimitiveArrayEncoder)
|
||||
}
|
||||
|
||||
func (l *ZapLogger) cores() (zap.Option, error) {
|
||||
fileEncoder := zapcore.NewJSONEncoder(zap.NewProductionEncoderConfig())
|
||||
c := zap.NewProductionEncoderConfig()
|
||||
c.EncodeTime = zapcore.ISO8601TimeEncoder
|
||||
c.EncodeDuration = zapcore.SecondsDurationEncoder
|
||||
//c.EncodeLevel = zapcore.LowercaseColorLevelEncoder
|
||||
fileEncoder := zapcore.NewJSONEncoder(c)
|
||||
fileEncoder.AddInt("PID", os.Getpid())
|
||||
writer, err := l.getWriter()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@@ -143,7 +145,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,12 +41,17 @@ 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)
|
||||
return s
|
||||
if ctx.Value(constant.OpUserID) != "" {
|
||||
s, ok := ctx.Value(constant.OpUserID).(string)
|
||||
if ok {
|
||||
return s
|
||||
}
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
func Unwrap(err error) error {
|
||||
|
||||
Reference in New Issue
Block a user