Skip to content

Commit

Permalink
Merge pull request #2357 from vincepri/log-stack-prefix
Browse files Browse the repository at this point in the history
馃尡 Add a prefix to the stack trace printed after SetLogger timeout
  • Loading branch information
k8s-ci-robot committed Jul 19, 2023
2 parents 283ebb6 + 761478a commit 93dd4b0
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion pkg/log/log.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ limitations under the License.
package log

import (
"bytes"
"context"
"fmt"
"os"
Expand All @@ -56,7 +57,15 @@ func eventuallyFulfillRoot() {
}
if time.Since(rootLogCreated).Seconds() >= 30 {
if logFullfilled.CompareAndSwap(false, true) {
fmt.Fprintf(os.Stderr, "[controller-runtime] log.SetLogger(...) was never called, logs will not be displayed:\n%s", debug.Stack())
stack := debug.Stack()
stackLines := bytes.Count(stack, []byte{'\n'})
sep := []byte{'\n', '\t', '>', ' ', ' '}

fmt.Fprintf(os.Stderr,
"[controller-runtime] log.SetLogger(...) was never called; logs will not be displayed.\nDetected at:%s%s", sep,
// prefix every line, so it's clear this is a stack trace related to the above message
bytes.Replace(stack, []byte{'\n'}, sep, stackLines-1),
)
SetLogger(logr.New(NullLogSink{}))
}
}
Expand Down

0 comments on commit 93dd4b0

Please sign in to comment.