Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

馃尡 Add a prefix to the stack trace printed after SetLogger timeout #2357

Merged
merged 1 commit into from
Jul 19, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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