Skip to content

Commit

Permalink
add Verbose.InfoSDepth
Browse files Browse the repository at this point in the history
It is needed in Kubernetes for code like this (from
k8s.io/apiserver/pkg/server/httplog/httplog.go):

  // Log is intended to be called once at the end of your request handler, via defer
  func (rl *respLogger) Log() {
          ...

          klog.V(withLoggingLevel).InfoSDepth(1, "HTTP", keysAndValues...)
  }

Without InfoSDepth as method for Verbose, such code has to use klog.InfoSDepth,
which records the message with v=0 in JSON output. This is the wrong verbosity
for this debug message.

We don't need Verbose.ErrorSDepth (error messages have no verbosity) and also
no Verbose.Info[f]Depth (when touching code, it should be rewritten to use
Verbose.InfoSDepth instead)
  • Loading branch information
pohly committed Dec 14, 2021
1 parent 9ad2462 commit b605dee
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions klog.go
Expand Up @@ -1387,6 +1387,14 @@ func InfoSDepth(depth int, msg string, keysAndValues ...interface{}) {
logging.infoS(logging.logr, logging.filter, depth, msg, keysAndValues...)
}

// InfoSDepth is equivalent to the global InfoSDepth function, guarded by the value of v.
// See the documentation of V for usage.
func (v Verbose) InfoSDepth(depth int, msg string, keysAndValues ...interface{}) {
if v.enabled {
logging.infoS(v.logr, v.filter, depth, msg, keysAndValues...)
}
}

// Deprecated: Use ErrorS instead.
func (v Verbose) Error(err error, msg string, args ...interface{}) {
if v.enabled {
Expand Down

0 comments on commit b605dee

Please sign in to comment.