-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlevelenabler.go
25 lines (22 loc) · 1.06 KB
/
levelenabler.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
package zaplog
import (
"go.uber.org/zap"
"go.uber.org/zap/zapcore"
)
var levelEnablerFuncMap = map[zapcore.Level]zap.LevelEnablerFunc{
zapcore.DebugLevel: func(level zapcore.Level) bool { return level == zap.DebugLevel }, // 调试级别
zapcore.InfoLevel: func(level zapcore.Level) bool { return level == zap.InfoLevel }, // 日志级别
zapcore.WarnLevel: func(level zapcore.Level) bool { return level == zap.WarnLevel }, // 警告级别
zapcore.ErrorLevel: func(level zapcore.Level) bool { return level == zap.ErrorLevel }, // 错误级别
zapcore.DPanicLevel: func(level zapcore.Level) bool { return level == zap.DPanicLevel }, // dpanic级别
zapcore.PanicLevel: func(level zapcore.Level) bool { return level == zap.PanicLevel }, // panic级别
zapcore.FatalLevel: func(level zapcore.Level) bool { return level == zap.FatalLevel }, // 终止级别
}
// GetLevelEnabler 获取日志强等过滤器
func GetLevelEnabler(level zapcore.Level) zapcore.LevelEnabler {
fn, found := levelEnablerFuncMap[level]
if !found {
return level
}
return fn
}