Skip to content

Commit

Permalink
klogr: pass verbosity level through to klog
Browse files Browse the repository at this point in the history
That wasn't (and still isn't) necessary when klog itself emits the log entry
because it doesn't log the verbosity. But when SetLogger was used to enabled
logging through a backend logger, that logger may care about the verbosity
level.
  • Loading branch information
pohly committed Feb 15, 2022
1 parent bb978b3 commit a58a994
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 7 deletions.
5 changes: 0 additions & 5 deletions examples/output_test/output_test.go
Expand Up @@ -21,7 +21,6 @@ package output_test

import (
"io"
"strings"
"testing"

"github.com/go-logr/logr"
Expand Down Expand Up @@ -112,10 +111,6 @@ func TestKlogrStackText(t *testing.T) {
// records that.
func TestKlogrStackZapr(t *testing.T) {
mapping := test.ZaprOutputMappingIndirect()
for key, value := range mapping {
// BUG (https://github.com/kubernetes/klog/issues/294): verbosity is lost
mapping[key] = strings.ReplaceAll(value, `"v":9`, `"v":0`)
}

// klogr doesn't warn about invalid KVs and just inserts
// "(MISSING)".
Expand Down
4 changes: 2 additions & 2 deletions klogr/klogr.go
Expand Up @@ -122,13 +122,13 @@ func (l klogger) Info(level int, msg string, kvList ...interface{}) {
trimmed := serialize.TrimDuplicates(l.values, kvList)
fixedStr := flatten(trimmed[0]...)
userStr := flatten(trimmed[1]...)
klog.InfoDepth(l.callDepth+1, l.prefix, " ", msgStr, " ", fixedStr, " ", userStr)
klog.V(klog.Level(level)).InfoDepth(l.callDepth+1, l.prefix, " ", msgStr, " ", fixedStr, " ", userStr)
case FormatKlog:
trimmed := serialize.TrimDuplicates(l.values, kvList)
if l.prefix != "" {
msg = l.prefix + ": " + msg
}
klog.InfoSDepth(l.callDepth+1, msg, append(trimmed[0], trimmed[1]...)...)
klog.V(klog.Level(level)).InfoSDepth(l.callDepth+1, msg, append(trimmed[0], trimmed[1]...)...)
}
}

Expand Down

0 comments on commit a58a994

Please sign in to comment.