1
0
Fork 0
mirror of https://github.com/kyverno/kyverno.git synced 2025-03-31 03:45:17 +00:00

fix: configure klog and global logger to use zapr in json mode (#5144)

* configure klog and global logger to use zapr in json mode

Signed-off-by: damilola olayinka <holayinkajr@gmail.com>

* changes

Signed-off-by: damilola olayinka <holayinkajr@gmail.com>

* make zapr compatible with klog's -v argument

Signed-off-by: damilola olayinka <holayinkajr@gmail.com>

* remove changes

Signed-off-by: damilola olayinka <holayinkajr@gmail.com>

* remove logLevel flag

Signed-off-by: damilola olayinka <holayinkajr@gmail.com>

Signed-off-by: damilola olayinka <holayinkajr@gmail.com>
Co-authored-by: shuting <shuting@nirmata.com>
This commit is contained in:
yinka 2022-10-28 21:52:58 +01:00 committed by GitHub
parent 1fef873762
commit 8a59e240c6
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -43,6 +43,7 @@ func Init(flags *flag.FlagSet) {
// Setup configures the logger with the supplied log format. // Setup configures the logger with the supplied log format.
// It returns an error if the JSON logger could not be initialized or passed logFormat is not recognized. // It returns an error if the JSON logger could not be initialized or passed logFormat is not recognized.
// LogLevel parameter is used to configure zap.
func Setup(logFormat string) error { func Setup(logFormat string) error {
switch logFormat { switch logFormat {
case TextFormat: case TextFormat:
@ -53,9 +54,9 @@ func Setup(logFormat string) error {
if err != nil { if err != nil {
return err return err
} }
klog.SetLogger(zapr.NewLogger(zapLog)) globalLog = zapr.NewLogger(zapLog)
// in json mode we use FormatKlog format // in json mode we configure klog and global logger to use zapr
globalLog = klog.NewKlogr() klog.SetLogger(globalLog.WithName("klog"))
default: default:
return errors.New("log format not recognized, pass `text` for text mode or `json` to enable JSON logging") return errors.New("log format not recognized, pass `text` for text mode or `json` to enable JSON logging")
} }