Repository: kubernetes/klog
Pull request #164 (2020-06-12 15:30:55)

feat use go-logr v0.2.0
<!--  Thanks for sending a pull request!  Here are some tips for you:
1. If this is your first time, read our contributor guidelines https://git.k8s.io/community/contributors/guide/pull-requests.md#the-pull-request-submit-process and developer guide https://git.k8s.io/community/contributors/devel/development.md#development-guide
2. If you want *faster* PR reviews, read how: https://git.k8s.io/community/contributors/guide/pull-requests.md#best-practices-for-faster-reviews
3. Follow the instructions for writing a release note: https://git.k8s.io/community/contributors/guide/release-notes.md
4. If the PR is unfinished, see how to mark it: https://git.k8s.io/community/contributors/guide/pull-requests.md#marking-unfinished-pull-requests
5. If this PR changes image versions, please title this PR "Bump <image name> from x.x.x to y.y.y."
-->

**What this PR does / why we need it**:

This PR upgrades go-logr to v0.2.0

_Please confirm that if this PR changes any image versions, then that's the sole change this PR makes._

**Release note**:
<!--  Write your release note:
1. Enter your extended release note in the below block. If the PR requires additional action from users switching to the new release, include the string "action required".
2. If no release note is required, just write "NONE".
-->
```release-note
upgrade go-logr dependency to v0.2.0
```


Patch:
diff --git a/go.mod b/go.mod
index f50b258..e396e31 100644
--- a/go.mod
+++ b/go.mod
@@ -2,4 +2,4 @@ module k8s.io/klog/v2
 
 go 1.13
 
-require github.com/go-logr/logr v0.1.0
+require github.com/go-logr/logr v0.2.0
diff --git a/go.sum b/go.sum
index fb64d27..8dfa785 100644
--- a/go.sum
+++ b/go.sum
@@ -1,2 +1,2 @@
-github.com/go-logr/logr v0.1.0 h1:M1Tv3VzNlEHg6uyACnRdtrploV2P7wZqH8BoQMtz0cg=
-github.com/go-logr/logr v0.1.0/go.mod h1:ixOQHD9gLJUVQQ2ZOR7zLEifBX6tGkNJF4QyIY7sIas=
+github.com/go-logr/logr v0.2.0 h1:QvGt2nLcHH0WK9orKa+ppBPAxREcH364nPUedEpK0TY=
+github.com/go-logr/logr v0.2.0/go.mod h1:z6/tIYblkpsD+a4lm/fGIIU9mZ+XfAiaFtq7xTgseGU=
diff --git a/klog.go b/klog.go
index d339ea8..b0091f4 100644
--- a/klog.go
+++ b/klog.go
@@ -687,7 +687,7 @@ func (buf *buffer) someDigits(i, d int) int {
 	return copy(buf.tmp[i:], buf.tmp[j:])
 }
 
-func (l *loggingT) println(s severity, logr logr.InfoLogger, args ...interface{}) {
+func (l *loggingT) println(s severity, logr logr.Logger, args ...interface{}) {
 	buf, file, line := l.header(s, 0)
 	// if logr is set, we clear the generated header as we rely on the backing
 	// logr implementation to print headers
@@ -699,11 +699,11 @@ func (l *loggingT) println(s severity, logr logr.InfoLogger, args ...interface{}
 	l.output(s, logr, buf, file, line, false)
 }
 
-func (l *loggingT) print(s severity, logr logr.InfoLogger, args ...interface{}) {
+func (l *loggingT) print(s severity, logr logr.Logger, args ...interface{}) {
 	l.printDepth(s, logr, 1, args...)
 }
 
-func (l *loggingT) printDepth(s severity, logr logr.InfoLogger, depth int, args ...interface{}) {
+func (l *loggingT) printDepth(s severity, logr logr.Logger, depth int, args ...interface{}) {
 	buf, file, line := l.header(s, depth)
 	// if logr is set, we clear the generated header as we rely on the backing
 	// logr implementation to print headers
@@ -718,7 +718,7 @@ func (l *loggingT) printDepth(s severity, logr logr.InfoLogger, depth int, args
 	l.output(s, logr, buf, file, line, false)
 }
 
-func (l *loggingT) printf(s severity, logr logr.InfoLogger, format string, args ...interface{}) {
+func (l *loggingT) printf(s severity, logr logr.Logger, format string, args ...interface{}) {
 	buf, file, line := l.header(s, 0)
 	// if logr is set, we clear the generated header as we rely on the backing
 	// logr implementation to print headers
@@ -736,7 +736,7 @@ func (l *loggingT) printf(s severity, logr logr.InfoLogger, format string, args
 // printWithFileLine behaves like print but uses the provided file and line number.  If
 // alsoLogToStderr is true, the log message always appears on standard error; it
 // will also appear in the log file unless --logtostderr is set.
-func (l *loggingT) printWithFileLine(s severity, logr logr.InfoLogger, file string, line int, alsoToStderr bool, args ...interface{}) {
+func (l *loggingT) printWithFileLine(s severity, logr logr.Logger, file string, line int, alsoToStderr bool, args ...interface{}) {
 	buf := l.formatHeader(s, file, line)
 	// if logr is set, we clear the generated header as we rely on the backing
 	// logr implementation to print headers
@@ -761,7 +761,7 @@ func (l *loggingT) errorS(err error, loggr logr.Logger, msg string, keysAndValue
 }
 
 // if loggr is specified, will call loggr.Info, otherwise output with logging module.
-func (l *loggingT) infoS(loggr logr.InfoLogger, msg string, keysAndValues ...interface{}) {
+func (l *loggingT) infoS(loggr logr.Logger, msg string, keysAndValues ...interface{}) {
 	if loggr != nil {
 		loggr.Info(msg, keysAndValues)
 		return
@@ -878,7 +878,7 @@ func LogToStderr(stderr bool) {
 }
 
 // output writes the data to the log files and releases the buffer.
-func (l *loggingT) output(s severity, log logr.InfoLogger, buf *buffer, file string, line int, alsoToStderr bool) {
+func (l *loggingT) output(s severity, log logr.Logger, buf *buffer, file string, line int, alsoToStderr bool) {
 	l.mu.Lock()
 	if l.traceLocation.isSet() {
 		if l.traceLocation.match(file, line) {
@@ -1231,7 +1231,7 @@ func (l *loggingT) setV(pc uintptr) Level {
 // See the documentation of V for more information.
 type Verbose struct {
 	enabled bool
-	logr    logr.InfoLogger
+	logr    logr.Logger
 }
 
 func newVerbose(level Level, b bool) Verbose {
@@ -1324,6 +1324,14 @@ func (v Verbose) InfoS(msg string, keysAndValues ...interface{}) {
 	}
 }
 
+// Error is equivalent to the global Error function, guarded by the value of v.
+// See the documentation of V for usage.
+func (v Verbose) Error(err error, msg string, args ...interface{}) {
+	if v.enabled {
+		logging.errorS(err, v.logr, msg, args...)
+	}
+}
+
 // Info logs to the INFO log.
 // Arguments are handled in the manner of fmt.Print; a newline is appended if missing.
 func Info(args ...interface{}) {
diff --git a/klogr/klogr.go b/klogr/klogr.go
index 9791cd8..227d07b 100644
--- a/klogr/klogr.go
+++ b/klogr/klogr.go
@@ -174,7 +174,7 @@ func (l klogger) Error(err error, msg string, kvList ...interface{}) {
 	klog.ErrorDepth(framesToCaller(), l.prefix, " ", msgStr, " ", errStr, " ", fixedStr, " ", userStr)
 }
 
-func (l klogger) V(level int) logr.InfoLogger {
+func (l klogger) V(level int) logr.Logger {
 	new := l.clone()
 	new.level = level
 	return new
@@ -199,4 +199,3 @@ func (l klogger) WithValues(kvList ...interface{}) logr.Logger {
 }
 
 var _ logr.Logger = klogger{}
-var _ logr.InfoLogger = klogger{}


Test patch:
diff --git a/klogr/klogr_test.go b/klogr/klogr_test.go
index 712ac9c..38b4410 100644
--- a/klogr/klogr_test.go
+++ b/klogr/klogr_test.go
@@ -22,7 +22,7 @@ func TestInfo(t *testing.T) {
 	flag.Parse()
 
 	tests := map[string]struct {
-		klogr          logr.InfoLogger
+		klogr          logr.Logger
 		text           string
 		keysAndValues  []interface{}
 		expectedOutput string