Skip to content

Commit

Permalink
fix: configure klog and global logger to use zapr in json mode (kyver…
Browse files Browse the repository at this point in the history
…no#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>
  • Loading branch information
yimikao and realshuting authored Oct 28, 2022
1 parent 1fef873 commit 8a59e24
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions pkg/logging/log.go
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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")
}
Expand Down

0 comments on commit 8a59e24

Please sign in to comment.