Skip to content

Commit 49123d4

Browse files
committedMay 29, 2020
ErrorS(nil, ...) should call loggr.Error(nil, ...)
1 parent 9e86e5a commit 49123d4

File tree

1 file changed

+22
-16
lines changed

1 file changed

+22
-16
lines changed
 

‎klog.go

+22-16
Original file line numberDiff line numberDiff line change
@@ -751,17 +751,27 @@ func (l *loggingT) printWithFileLine(s severity, logr logr.InfoLogger, file stri
751751
l.output(s, logr, buf, file, line, alsoToStderr)
752752
}
753753

754-
// printS if loggr is specified, no need to output with logging module. If
755-
// err arguments is specified, will call logr.Error, or output to errorLog severity
756-
func (l *loggingT) printS(err error, loggr logr.Logger, msg string, keysAndValues ...interface{}) {
754+
// if loggr is specified, will call loggr.Error, otherwise output with logging module.
755+
func (l *loggingT) errorS(err error, loggr logr.Logger, msg string, keysAndValues ...interface{}) {
757756
if loggr != nil {
758-
if err != nil {
759-
loggr.Error(err, msg, keysAndValues)
760-
} else {
761-
loggr.Info(msg, keysAndValues)
762-
}
757+
loggr.Error(err, msg, keysAndValues)
763758
return
764759
}
760+
l.printS(err, msg, keysAndValues...)
761+
}
762+
763+
// 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{}) {
765+
if loggr != nil {
766+
loggr.Info(msg, keysAndValues)
767+
return
768+
}
769+
l.printS(nil, msg, keysAndValues...)
770+
}
771+
772+
// printS is called from infoS and errorS if loggr is not specified.
773+
// if err arguments is specified, will output to errorLog severity
774+
func (l *loggingT) printS(err error, msg string, keysAndValues ...interface{}) {
765775
b := &bytes.Buffer{}
766776
b.WriteString(fmt.Sprintf("%q", msg))
767777
if err != nil {
@@ -775,7 +785,7 @@ func (l *loggingT) printS(err error, loggr logr.Logger, msg string, keysAndValue
775785
} else {
776786
s = errorLog
777787
}
778-
l.printDepth(s, logging.logr, 1, b)
788+
l.printDepth(s, logging.logr, 2, b)
779789
}
780790

781791
const missingValue = "(MISSING)"
@@ -1304,11 +1314,7 @@ func (v Verbose) Infof(format string, args ...interface{}) {
13041314
// See the documentation of V for usage.
13051315
func (v Verbose) InfoS(msg string, keysAndValues ...interface{}) {
13061316
if v.enabled {
1307-
if v.logr != nil {
1308-
v.logr.Info(msg, keysAndValues)
1309-
return
1310-
}
1311-
logging.printS(nil, nil, msg, keysAndValues...)
1317+
logging.infoS(v.logr, msg, keysAndValues)
13121318
}
13131319
}
13141320

@@ -1345,7 +1351,7 @@ func Infof(format string, args ...interface{}) {
13451351
// output:
13461352
// >> I1025 00:15:15.525108 1 controller_utils.go:116] "Pod status updated" pod="kubedns" status="ready"
13471353
func InfoS(msg string, keysAndValues ...interface{}) {
1348-
logging.printS(nil, logging.logr, msg, keysAndValues...)
1354+
logging.infoS(logging.logr, msg, keysAndValues...)
13491355
}
13501356

13511357
// Warning logs to the WARNING and INFO logs.
@@ -1406,7 +1412,7 @@ func Errorf(format string, args ...interface{}) {
14061412
// output:
14071413
// >> E1025 00:15:15.525108 1 controller_utils.go:114] "Failed to update pod status" err="timeout"
14081414
func ErrorS(err error, msg string, keysAndValues ...interface{}) {
1409-
logging.printS(err, logging.logr, msg, keysAndValues...)
1415+
logging.errorS(err, logging.logr, msg, keysAndValues...)
14101416
}
14111417

14121418
// Fatal logs to the FATAL, ERROR, WARNING, and INFO logs,

0 commit comments

Comments
 (0)
Please sign in to comment.