From 2544562363d4467106c645d97b96bdf3ae7499a6 Mon Sep 17 00:00:00 2001 From: Vince Prignano Date: Fri, 26 May 2023 08:20:10 -0700 Subject: [PATCH] Add a prefix to the stack trace printed after SetLogger timeout Signed-off-by: Vince Prignano --- pkg/log/log.go | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/pkg/log/log.go b/pkg/log/log.go index a79151c69e..778bd1f0b9 100644 --- a/pkg/log/log.go +++ b/pkg/log/log.go @@ -34,6 +34,7 @@ limitations under the License. package log import ( + "bytes" "context" "fmt" "os" @@ -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:%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{})) } }