mirror of
https://github.com/kyverno/kyverno.git
synced 2025-03-31 03:45:17 +00:00
fix: rename level 1 logs to INFO from DEBUG (#10617)
Signed-off-by: Vishal Choudhary <vishal.choudhary@nirmata.com> Co-authored-by: shuting <shuting@nirmata.com>
This commit is contained in:
parent
429b05544a
commit
9904718d08
1 changed files with 20 additions and 0 deletions
|
@ -59,8 +59,10 @@ func Setup(logFormat string, loggingTimestampFormat string, level int) error {
|
|||
switch logFormat {
|
||||
case TextFormat:
|
||||
zc = zap.NewDevelopmentConfig()
|
||||
zc.EncoderConfig.EncodeLevel = zapLevelEncoderText
|
||||
case JSONFormat:
|
||||
zc = zap.NewProductionConfig()
|
||||
zc.EncoderConfig.EncodeLevel = zapLevelEncoderJson
|
||||
default:
|
||||
return errors.New("log format not recognized, pass `text` for text mode or `json` to enable JSON logging")
|
||||
}
|
||||
|
@ -186,3 +188,21 @@ func (a *writerAdapter) Write(p []byte) (int, error) {
|
|||
func StdLogger(logger logr.Logger, prefix string) *stdlog.Logger {
|
||||
return stdlog.New(&writerAdapter{logger: logger}, prefix, stdlog.LstdFlags)
|
||||
}
|
||||
|
||||
func zapLevelEncoderText(l zapcore.Level, enc zapcore.PrimitiveArrayEncoder) {
|
||||
enc.AppendString(zapLevelToString(l))
|
||||
}
|
||||
|
||||
func zapLevelEncoderJson(l zapcore.Level, enc zapcore.PrimitiveArrayEncoder) {
|
||||
enc.AppendString(strings.ToLower(zapLevelToString(l)))
|
||||
}
|
||||
|
||||
func zapLevelToString(zapLevel zapcore.Level) string {
|
||||
if zapLevel <= 0 && zapLevel >= -2 {
|
||||
return "INFO"
|
||||
} else if zapLevel <= -3 {
|
||||
return "DEBUG"
|
||||
} else {
|
||||
return zapLevel.CapitalString()
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue