Skip to content

Commit 966c986

Browse files
committedJun 12, 2020
feat use go-logr v0.2.0
Signed-off-by: Yoan Blanc <yoan@dosimple.ch>
1 parent 825bd2f commit 966c986

File tree

5 files changed

+21
-14
lines changed

5 files changed

+21
-14
lines changed
 

‎go.mod

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@ module k8s.io/klog/v2
22

33
go 1.13
44

5-
require github.com/go-logr/logr v0.1.0
5+
require github.com/go-logr/logr v0.2.0

‎go.sum

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
github.com/go-logr/logr v0.1.0 h1:M1Tv3VzNlEHg6uyACnRdtrploV2P7wZqH8BoQMtz0cg=
2-
github.com/go-logr/logr v0.1.0/go.mod h1:ixOQHD9gLJUVQQ2ZOR7zLEifBX6tGkNJF4QyIY7sIas=
1+
github.com/go-logr/logr v0.2.0 h1:QvGt2nLcHH0WK9orKa+ppBPAxREcH364nPUedEpK0TY=
2+
github.com/go-logr/logr v0.2.0/go.mod h1:z6/tIYblkpsD+a4lm/fGIIU9mZ+XfAiaFtq7xTgseGU=

‎klog.go

+16-8
Original file line numberDiff line numberDiff line change
@@ -687,7 +687,7 @@ func (buf *buffer) someDigits(i, d int) int {
687687
return copy(buf.tmp[i:], buf.tmp[j:])
688688
}
689689

690-
func (l *loggingT) println(s severity, logr logr.InfoLogger, args ...interface{}) {
690+
func (l *loggingT) println(s severity, logr logr.Logger, args ...interface{}) {
691691
buf, file, line := l.header(s, 0)
692692
// if logr is set, we clear the generated header as we rely on the backing
693693
// logr implementation to print headers
@@ -699,11 +699,11 @@ func (l *loggingT) println(s severity, logr logr.InfoLogger, args ...interface{}
699699
l.output(s, logr, buf, file, line, false)
700700
}
701701

702-
func (l *loggingT) print(s severity, logr logr.InfoLogger, args ...interface{}) {
702+
func (l *loggingT) print(s severity, logr logr.Logger, args ...interface{}) {
703703
l.printDepth(s, logr, 1, args...)
704704
}
705705

706-
func (l *loggingT) printDepth(s severity, logr logr.InfoLogger, depth int, args ...interface{}) {
706+
func (l *loggingT) printDepth(s severity, logr logr.Logger, depth int, args ...interface{}) {
707707
buf, file, line := l.header(s, depth)
708708
// if logr is set, we clear the generated header as we rely on the backing
709709
// logr implementation to print headers
@@ -718,7 +718,7 @@ func (l *loggingT) printDepth(s severity, logr logr.InfoLogger, depth int, args
718718
l.output(s, logr, buf, file, line, false)
719719
}
720720

721-
func (l *loggingT) printf(s severity, logr logr.InfoLogger, format string, args ...interface{}) {
721+
func (l *loggingT) printf(s severity, logr logr.Logger, format string, args ...interface{}) {
722722
buf, file, line := l.header(s, 0)
723723
// if logr is set, we clear the generated header as we rely on the backing
724724
// logr implementation to print headers
@@ -736,7 +736,7 @@ func (l *loggingT) printf(s severity, logr logr.InfoLogger, format string, args
736736
// printWithFileLine behaves like print but uses the provided file and line number. If
737737
// alsoLogToStderr is true, the log message always appears on standard error; it
738738
// will also appear in the log file unless --logtostderr is set.
739-
func (l *loggingT) printWithFileLine(s severity, logr logr.InfoLogger, file string, line int, alsoToStderr bool, args ...interface{}) {
739+
func (l *loggingT) printWithFileLine(s severity, logr logr.Logger, file string, line int, alsoToStderr bool, args ...interface{}) {
740740
buf := l.formatHeader(s, file, line)
741741
// if logr is set, we clear the generated header as we rely on the backing
742742
// logr implementation to print headers
@@ -761,7 +761,7 @@ func (l *loggingT) errorS(err error, loggr logr.Logger, msg string, keysAndValue
761761
}
762762

763763
// if loggr is specified, will call loggr.Info, otherwise output with logging module.
764-
func (l *loggingT) infoS(loggr logr.InfoLogger, msg string, keysAndValues ...interface{}) {
764+
func (l *loggingT) infoS(loggr logr.Logger, msg string, keysAndValues ...interface{}) {
765765
if loggr != nil {
766766
loggr.Info(msg, keysAndValues)
767767
return
@@ -878,7 +878,7 @@ func LogToStderr(stderr bool) {
878878
}
879879

880880
// output writes the data to the log files and releases the buffer.
881-
func (l *loggingT) output(s severity, log logr.InfoLogger, buf *buffer, file string, line int, alsoToStderr bool) {
881+
func (l *loggingT) output(s severity, log logr.Logger, buf *buffer, file string, line int, alsoToStderr bool) {
882882
l.mu.Lock()
883883
if l.traceLocation.isSet() {
884884
if l.traceLocation.match(file, line) {
@@ -1231,7 +1231,7 @@ func (l *loggingT) setV(pc uintptr) Level {
12311231
// See the documentation of V for more information.
12321232
type Verbose struct {
12331233
enabled bool
1234-
logr logr.InfoLogger
1234+
logr logr.Logger
12351235
}
12361236

12371237
func newVerbose(level Level, b bool) Verbose {
@@ -1324,6 +1324,14 @@ func (v Verbose) InfoS(msg string, keysAndValues ...interface{}) {
13241324
}
13251325
}
13261326

1327+
// Error is equivalent to the global Error function, guarded by the value of v.
1328+
// See the documentation of V for usage.
1329+
func (v Verbose) Error(err error, msg string, args ...interface{}) {
1330+
if v.enabled {
1331+
logging.errorS(err, v.logr, msg, args...)
1332+
}
1333+
}
1334+
13271335
// Info logs to the INFO log.
13281336
// Arguments are handled in the manner of fmt.Print; a newline is appended if missing.
13291337
func Info(args ...interface{}) {

‎klogr/klogr.go

+1-2
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,7 @@ func (l klogger) Error(err error, msg string, kvList ...interface{}) {
174174
klog.ErrorDepth(framesToCaller(), l.prefix, " ", msgStr, " ", errStr, " ", fixedStr, " ", userStr)
175175
}
176176

177-
func (l klogger) V(level int) logr.InfoLogger {
177+
func (l klogger) V(level int) logr.Logger {
178178
new := l.clone()
179179
new.level = level
180180
return new
@@ -199,4 +199,3 @@ func (l klogger) WithValues(kvList ...interface{}) logr.Logger {
199199
}
200200

201201
var _ logr.Logger = klogger{}
202-
var _ logr.InfoLogger = klogger{}

‎klogr/klogr_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ func TestInfo(t *testing.T) {
2222
flag.Parse()
2323

2424
tests := map[string]struct {
25-
klogr logr.InfoLogger
25+
klogr logr.Logger
2626
text string
2727
keysAndValues []interface{}
2828
expectedOutput string

0 commit comments

Comments
 (0)
Please sign in to comment.