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:
parent
1fef873762
commit
8a59e240c6
1 changed files with 4 additions and 3 deletions
|
@ -43,6 +43,7 @@ func Init(flags *flag.FlagSet) {
|
|||
|
||||
// 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.
|
||||
// LogLevel parameter is used to configure zap.
|
||||
func Setup(logFormat string) error {
|
||||
switch logFormat {
|
||||
case TextFormat:
|
||||
|
@ -53,9 +54,9 @@ func Setup(logFormat string) error {
|
|||
if err != nil {
|
||||
return err
|
||||
}
|
||||
klog.SetLogger(zapr.NewLogger(zapLog))
|
||||
// in json mode we use FormatKlog format
|
||||
globalLog = klog.NewKlogr()
|
||||
globalLog = zapr.NewLogger(zapLog)
|
||||
// in json mode we configure klog and global logger to use zapr
|
||||
klog.SetLogger(globalLog.WithName("klog"))
|
||||
default:
|
||||
return errors.New("log format not recognized, pass `text` for text mode or `json` to enable JSON logging")
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue