Skip to content

Commit

Permalink
refactor(logger): zapcore parse level
Browse files Browse the repository at this point in the history
  • Loading branch information
iyear committed Aug 6, 2022
1 parent 1e85599 commit 37afebd
Showing 1 changed file with 4 additions and 7 deletions.
11 changes: 4 additions & 7 deletions pkg/logger/logger.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,10 @@ func New(enable bool, filename, level string) *zap.SugaredLogger {
writeSyncer := getLogWriter(filename)
encoder := getEncoder()

levels := map[string]zapcore.Level{
"debug": zapcore.DebugLevel,
"info": zapcore.InfoLevel,
"warn": zapcore.WarnLevel,
"error": zapcore.ErrorLevel,
"fatal": zapcore.FatalLevel,
l, err := zapcore.ParseLevel(level)
if err != nil {
l = zapcore.InfoLevel
}
core := zapcore.NewCore(encoder, writeSyncer, levels[level])
core := zapcore.NewCore(encoder, writeSyncer, l)
return zap.New(core, zap.AddCaller()).Sugar()
}

0 comments on commit 37afebd

Please sign in to comment.