Skip to content

Commit 2544562

Browse files
committed
Add a prefix to the stack trace printed after SetLogger timeout
Signed-off-by: Vince Prignano <[email protected]>
1 parent 30eae58 commit 2544562

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

pkg/log/log.go

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ limitations under the License.
3434
package log
3535

3636
import (
37+
"bytes"
3738
"context"
3839
"fmt"
3940
"os"
@@ -56,7 +57,15 @@ func eventuallyFulfillRoot() {
5657
}
5758
if time.Since(rootLogCreated).Seconds() >= 30 {
5859
if logFullfilled.CompareAndSwap(false, true) {
59-
fmt.Fprintf(os.Stderr, "[controller-runtime] log.SetLogger(...) was never called, logs will not be displayed:\n%s", debug.Stack())
60+
stack := debug.Stack()
61+
stackLines := bytes.Count(stack, []byte{'\n'})
62+
sep := []byte{'\n', '\t', '>', ' ', ' '}
63+
64+
fmt.Fprintf(os.Stderr,
65+
"[controller-runtime] log.SetLogger(...) was never called, logs will not be displayed:%s%s", sep,
66+
// prefix every line, so it's clear this is a stack trace related to the above message
67+
bytes.Replace(stack, []byte{'\n'}, sep, stackLines-1),
68+
)
6069
SetLogger(logr.New(NullLogSink{}))
6170
}
6271
}

0 commit comments

Comments
 (0)