我看到 Uber Zap 实现中有日志级别:
const (
// DebugLevel logs are typically voluminous, and are usually disabled in
// production.
DebugLevel Level = iota - 1
// InfoLevel is the default logging priority.
InfoLevel
// WarnLevel logs are more important than Info, but don't need individual
// human review.
WarnLevel
// ErrorLevel logs are high-priority. If an application is running smoothly,
// it shouldn't generate any error-level logs.
ErrorLevel
// DPanicLevel logs are particularly important errors. In development the
// logger panics after writing the message.
DPanicLevel
// PanicLevel logs a message, then panics.
PanicLevel
// FatalLevel logs a message, then calls os.Exit(1).
FatalLevel
)
当我在sigs.k8s.io/controller-runtime/pkg/log/zap
记录器中设置级别时使用它,它go-logr
在引擎盖下使用:
func determineLogLevel(verbosityLevel string) zapcore.Level {
var zapLevel zapcore.Level
verbosityLevel = strings.ToLower(verbosityLevel)
switch verbosityLevel {
case ERROR:
zapLevel = zapcore.ErrorLevel
case WARNING:
zapLevel = zapcore.WarnLevel
case INFO:
zapLevel = zapcore.InfoLevel
case DEBUG:
zapLevel = zapcore.DebugLevel
default:
zapLevel = zapcore.InfoLevel
}
return zapLevel
}
// here zap is "sigs.k8s.io/controller-runtime/pkg/log/zap"
opts := zap.Options{
StacktraceLevel: ... ,
Level: determineLogLevel("ERROR"),
Encoder: ... ,
ZapOpts: ...,
}
但也可以选择使用logr.Logger.V
.
这里的水平值与 Uber Zap 的常量中的值相同吗?( DebugLevel
, InfoLevel
, WarnLevel
, ....)
我也看到了这个:
flag --zap-log-level:Zap 级别以配置日志记录的详细程度。可以是“调试”、“信息”、“错误”或任何大于 0 的整数值之一,对应于增加详细程度的自定义调试级别”</p>
此标志值是否与'szapcore.Level
中的相同?sigs.k8s.io
zap.Options
// V returns an Logger value for a specific verbosity level, relative to
// this Logger. In other words, V values are additive. V higher verbosity
// level means a log message is less important. It's illegal to pass a log
// level less than zero.
V(level int) Logger