Skip to content

Commit

Permalink
Add a prefix to the stack trace printed after SetLogger timeout
Browse files Browse the repository at this point in the history
Signed-off-by: Vince Prignano <vincepri@redhat.com>
  • Loading branch information
vincepri committed May 26, 2023
1 parent 30eae58 commit 95885c7
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 95885c7

Please sign in to comment.