mirror of
https://github.com/ceph/ceph-csi.git
synced 2025-06-13 10:33:35 +00:00
rebase: bump k8s.io/klog/v2 from 2.30.0 to 2.40.1
Bumps [k8s.io/klog/v2](https://github.com/kubernetes/klog) from 2.30.0 to 2.40.1. - [Release notes](https://github.com/kubernetes/klog/releases) - [Changelog](https://github.com/kubernetes/klog/blob/main/RELEASE.md) - [Commits](https://github.com/kubernetes/klog/compare/v2.30.0...v2.40.1) --- updated-dependencies: - dependency-name: k8s.io/klog/v2 dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] <support@github.com>
This commit is contained in:
committed by
mergify[bot]
parent
bbce265ead
commit
c313fcd69d
150
vendor/k8s.io/klog/v2/klog.go
generated
vendored
150
vendor/k8s.io/klog/v2/klog.go
generated
vendored
@ -801,14 +801,19 @@ func (l *loggingT) infoS(logger *logr.Logger, filter LogFilter, depth int, msg s
|
||||
// printS is called from infoS and errorS if loggr is not specified.
|
||||
// set log severity by s
|
||||
func (l *loggingT) printS(err error, s severity, depth int, msg string, keysAndValues ...interface{}) {
|
||||
b := &bytes.Buffer{}
|
||||
b.WriteString(fmt.Sprintf("%q", msg))
|
||||
// Only create a new buffer if we don't have one cached.
|
||||
b := l.getBuffer()
|
||||
// The message is always quoted, even if it contains line breaks.
|
||||
// If developers want multi-line output, they should use a small, fixed
|
||||
// message and put the multi-line output into a value.
|
||||
b.WriteString(strconv.Quote(msg))
|
||||
if err != nil {
|
||||
b.WriteByte(' ')
|
||||
b.WriteString(fmt.Sprintf("err=%q", err.Error()))
|
||||
kvListFormat(&b.Buffer, "err", err)
|
||||
}
|
||||
kvListFormat(b, keysAndValues...)
|
||||
l.printDepth(s, logging.logr, nil, depth+1, b)
|
||||
kvListFormat(&b.Buffer, keysAndValues...)
|
||||
l.printDepth(s, logging.logr, nil, depth+1, &b.Buffer)
|
||||
// Make the buffer available for reuse.
|
||||
l.putBuffer(b)
|
||||
}
|
||||
|
||||
const missingValue = "(MISSING)"
|
||||
@ -823,19 +828,106 @@ func kvListFormat(b *bytes.Buffer, keysAndValues ...interface{}) {
|
||||
v = missingValue
|
||||
}
|
||||
b.WriteByte(' ')
|
||||
|
||||
switch v.(type) {
|
||||
case string, error:
|
||||
b.WriteString(fmt.Sprintf("%s=%q", k, v))
|
||||
case []byte:
|
||||
b.WriteString(fmt.Sprintf("%s=%+q", k, v))
|
||||
default:
|
||||
if _, ok := v.(fmt.Stringer); ok {
|
||||
b.WriteString(fmt.Sprintf("%s=%q", k, v))
|
||||
} else {
|
||||
b.WriteString(fmt.Sprintf("%s=%+v", k, v))
|
||||
}
|
||||
// Keys are assumed to be well-formed according to
|
||||
// https://github.com/kubernetes/community/blob/master/contributors/devel/sig-instrumentation/migration-to-structured-logging.md#name-arguments
|
||||
// for the sake of performance. Keys with spaces,
|
||||
// special characters, etc. will break parsing.
|
||||
if k, ok := k.(string); ok {
|
||||
// Avoid one allocation when the key is a string, which
|
||||
// normally it should be.
|
||||
b.WriteString(k)
|
||||
} else {
|
||||
b.WriteString(fmt.Sprintf("%s", k))
|
||||
}
|
||||
|
||||
// The type checks are sorted so that more frequently used ones
|
||||
// come first because that is then faster in the common
|
||||
// cases. In Kubernetes, ObjectRef (a Stringer) is more common
|
||||
// than plain strings
|
||||
// (https://github.com/kubernetes/kubernetes/pull/106594#issuecomment-975526235).
|
||||
switch v := v.(type) {
|
||||
case fmt.Stringer:
|
||||
writeStringValue(b, true, stringerToString(v))
|
||||
case string:
|
||||
writeStringValue(b, true, v)
|
||||
case error:
|
||||
writeStringValue(b, true, v.Error())
|
||||
case []byte:
|
||||
// In https://github.com/kubernetes/klog/pull/237 it was decided
|
||||
// to format byte slices with "%+q". The advantages of that are:
|
||||
// - readable output if the bytes happen to be printable
|
||||
// - non-printable bytes get represented as unicode escape
|
||||
// sequences (\uxxxx)
|
||||
//
|
||||
// The downsides are that we cannot use the faster
|
||||
// strconv.Quote here and that multi-line output is not
|
||||
// supported. If developers know that a byte array is
|
||||
// printable and they want multi-line output, they can
|
||||
// convert the value to string before logging it.
|
||||
b.WriteByte('=')
|
||||
b.WriteString(fmt.Sprintf("%+q", v))
|
||||
default:
|
||||
writeStringValue(b, false, fmt.Sprintf("%+v", v))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func stringerToString(s fmt.Stringer) (ret string) {
|
||||
defer func() {
|
||||
if err := recover(); err != nil {
|
||||
ret = "nil"
|
||||
}
|
||||
}()
|
||||
ret = s.String()
|
||||
return
|
||||
}
|
||||
|
||||
func writeStringValue(b *bytes.Buffer, quote bool, v string) {
|
||||
data := []byte(v)
|
||||
index := bytes.IndexByte(data, '\n')
|
||||
if index == -1 {
|
||||
b.WriteByte('=')
|
||||
if quote {
|
||||
// Simple string, quote quotation marks and non-printable characters.
|
||||
b.WriteString(strconv.Quote(v))
|
||||
return
|
||||
}
|
||||
// Non-string with no line breaks.
|
||||
b.WriteString(v)
|
||||
return
|
||||
}
|
||||
|
||||
// Complex multi-line string, show as-is with indention like this:
|
||||
// I... "hello world" key=<
|
||||
// <tab>line 1
|
||||
// <tab>line 2
|
||||
// >
|
||||
//
|
||||
// Tabs indent the lines of the value while the end of string delimiter
|
||||
// is indented with a space. That has two purposes:
|
||||
// - visual difference between the two for a human reader because indention
|
||||
// will be different
|
||||
// - no ambiguity when some value line starts with the end delimiter
|
||||
//
|
||||
// One downside is that the output cannot distinguish between strings that
|
||||
// end with a line break and those that don't because the end delimiter
|
||||
// will always be on the next line.
|
||||
b.WriteString("=<\n")
|
||||
for index != -1 {
|
||||
b.WriteByte('\t')
|
||||
b.Write(data[0 : index+1])
|
||||
data = data[index+1:]
|
||||
index = bytes.IndexByte(data, '\n')
|
||||
}
|
||||
if len(data) == 0 {
|
||||
// String ended with line break, don't add another.
|
||||
b.WriteString(" >")
|
||||
} else {
|
||||
// No line break at end of last line, write rest of string and
|
||||
// add one.
|
||||
b.WriteByte('\t')
|
||||
b.Write(data)
|
||||
b.WriteString("\n >")
|
||||
}
|
||||
}
|
||||
|
||||
@ -917,7 +1009,15 @@ func LogToStderr(stderr bool) {
|
||||
|
||||
// output writes the data to the log files and releases the buffer.
|
||||
func (l *loggingT) output(s severity, log *logr.Logger, buf *buffer, depth int, file string, line int, alsoToStderr bool) {
|
||||
var isLocked = true
|
||||
l.mu.Lock()
|
||||
defer func() {
|
||||
if isLocked {
|
||||
// Unlock before returning in case that it wasn't done already.
|
||||
l.mu.Unlock()
|
||||
}
|
||||
}()
|
||||
|
||||
if l.traceLocation.isSet() {
|
||||
if l.traceLocation.match(file, line) {
|
||||
buf.Write(stacks(false))
|
||||
@ -980,6 +1080,7 @@ func (l *loggingT) output(s severity, log *logr.Logger, buf *buffer, depth int,
|
||||
// If we got here via Exit rather than Fatal, print no stacks.
|
||||
if atomic.LoadUint32(&fatalNoStacks) > 0 {
|
||||
l.mu.Unlock()
|
||||
isLocked = false
|
||||
timeoutFlush(10 * time.Second)
|
||||
os.Exit(1)
|
||||
}
|
||||
@ -997,11 +1098,12 @@ func (l *loggingT) output(s severity, log *logr.Logger, buf *buffer, depth int,
|
||||
}
|
||||
}
|
||||
l.mu.Unlock()
|
||||
isLocked = false
|
||||
timeoutFlush(10 * time.Second)
|
||||
os.Exit(255) // C++ uses -1, which is silly because it's anded with 255 anyway.
|
||||
os.Exit(255) // C++ uses -1, which is silly because it's anded(&) with 255 anyway.
|
||||
}
|
||||
l.putBuffer(buf)
|
||||
l.mu.Unlock()
|
||||
|
||||
if stats := severityStats[s]; stats != nil {
|
||||
atomic.AddInt64(&stats.lines, 1)
|
||||
atomic.AddInt64(&stats.bytes, int64(len(data)))
|
||||
@ -1387,6 +1489,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 {
|
||||
|
Reference in New Issue
Block a user