Skip to content

Commit

Permalink
Merge pull request #137 from openimsdk/bug
Browse files Browse the repository at this point in the history
fix: implement the fmt.Stringer interface. when it is nil, it will handle the crash caused by the implementation
  • Loading branch information
withchao authored Oct 11, 2024
2 parents b6cc640 + 6cc7fee commit 61e6280
Showing 1 changed file with 2 additions and 8 deletions.
10 changes: 2 additions & 8 deletions log/zap.go
Original file line number Diff line number Diff line change
Expand Up @@ -350,7 +350,7 @@ func (l *ZapLogger) capitalColorLevelEncoder(level zapcore.Level, enc zapcore.Pr
if !ok {
s = _unknownLevelColor[zapcore.ErrorLevel]
}
pid := stringutil.FormatString(fmt.Sprintf("["+"PID:"+"%d"+"]", os.Getpid()), 15, true)
pid := stringutil.FormatString(fmt.Sprintf("[PID:%d]", os.Getpid()), 15, true)
color := _levelToColor[level]
enc.AppendString(s)
enc.AppendString(color.Add(pid))
Expand All @@ -359,7 +359,7 @@ func (l *ZapLogger) capitalColorLevelEncoder(level zapcore.Level, enc zapcore.Pr
enc.AppendString(color.Add(moduleName))
}
if l.moduleVersion != "" {
moduleVersion := stringutil.FormatString(fmt.Sprintf("["+"version:"+"%s"+"]", l.moduleVersion), 17, true)
moduleVersion := stringutil.FormatString(fmt.Sprintf("[%s]", l.moduleVersion), 30, true)
enc.AppendString(moduleVersion)
}
}
Expand Down Expand Up @@ -430,12 +430,6 @@ func (l *ZapLogger) kvAppend(ctx context.Context, keysAndValues []any) []any {
}
}

for i := 1; i < len(keysAndValues); i += 2 {
if s, ok := keysAndValues[i].(interface{ String() string }); ok {
keysAndValues[i] = s.String()
}
}

if opUserID != "" {
keysAndValues = append([]any{constant.OpUserID, opUserID}, keysAndValues...)
}
Expand Down

0 comments on commit 61e6280

Please sign in to comment.