Skip to content

Commit

Permalink
perf(zap): use switch
Browse files Browse the repository at this point in the history
Signed-off-by: rogerogers <[email protected]>
  • Loading branch information
rogerogers committed Jun 22, 2024
1 parent 04e700c commit 329523e
Showing 1 changed file with 15 additions and 14 deletions.
29 changes: 15 additions & 14 deletions zap/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,20 +30,21 @@ func InArray(key ExtraKey, arr []ExtraKey) bool {
return false
}

var hLevelToZapLevelMap = map[hlog.Level]zapcore.Level{
hlog.LevelTrace: zapcore.DebugLevel,
hlog.LevelDebug: zapcore.DebugLevel,
hlog.LevelInfo: zapcore.InfoLevel,
hlog.LevelNotice: zapcore.WarnLevel,
hlog.LevelWarn: zapcore.WarnLevel,
hlog.LevelError: zapcore.ErrorLevel,
hlog.LevelFatal: zapcore.FatalLevel,
}

func hLevelToZapLevel(level hlog.Level) zapcore.Level {
if zapLevel, ok := hLevelToZapLevelMap[level]; ok {
return zapLevel
var lvl zapcore.Level
switch level {
case hlog.LevelTrace, hlog.LevelDebug:
lvl = zap.DebugLevel
case hlog.LevelInfo:
lvl = zap.InfoLevel
case hlog.LevelWarn, hlog.LevelNotice:
lvl = zap.WarnLevel
case hlog.LevelError:
lvl = zap.ErrorLevel
case hlog.LevelFatal:
lvl = zap.FatalLevel
default:
lvl = zap.WarnLevel
}

return zap.WarnLevel
return lvl
}

0 comments on commit 329523e

Please sign in to comment.