升级log_level处理

This commit is contained in:
2024-06-24 17:54:31 +08:00
parent 16d33f84ca
commit 408f33b21e
3 changed files with 38 additions and 37 deletions

View File

@ -8,8 +8,10 @@
package logger
import (
"git.zhangdeman.cn/zhangdeman/consts"
"io"
"os"
"strings"
"github.com/pkg/errors"
@ -25,11 +27,26 @@ import (
// Author : go_developer@163.com<白茶清欢>
//
// Date : 5:05 下午 2021/1/2
func NewLogger(loggerLevel zapcore.Level, splitConfig *RotateLogConfig, optionFunc ...SetLoggerOptionFunc) (*zap.Logger, error) {
func NewLogger(inputLoggerLevel string, splitConfig *RotateLogConfig, optionFunc ...SetLoggerOptionFunc) (*zap.Logger, error) {
if nil == splitConfig {
return nil, errors.New("未配置日志切割规则")
}
loggerLevel := zapcore.DebugLevel
switch strings.ToUpper(inputLoggerLevel) {
case consts.LogLevelDebug:
loggerLevel = zapcore.DebugLevel
case consts.LogLevelInfo:
loggerLevel = zapcore.InfoLevel
case consts.LogLevelWarn:
loggerLevel = zapcore.WarnLevel
case consts.LogLevelError:
loggerLevel = zapcore.ErrorLevel
case consts.LogLevelPanic:
loggerLevel = zapcore.PanicLevel
default:
return nil, errors.New(inputLoggerLevel + " : input log level is not support")
}
o := &OptionLogger{}
for _, f := range optionFunc {