Skip to content
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: 11 additions & 0 deletions logging/cyclicWriter.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (
"os"
"os/exec"
"path/filepath"
"runtime"
"strings"
"text/template"
"time"
Expand Down Expand Up @@ -124,6 +125,16 @@ func (cyclic *CyclicFileWriter) Write(p []byte) (n int, err error) {

if uint64(len(p)) > cyclic.limit {
// there's no hope for writing this entry to the log

// for the large lines this is a clear indication something does wrong, dump data into stderr
const minDebugLogLineSize = 10 * 1024 * 1024
if len(p) >= minDebugLogLineSize {
buf := make([]byte, 16*1024)
stlen := runtime.Stack(buf, false)
Comment on lines +132 to +133
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: debug.Stack() manages making a buffer for runtime.Stack() on your behalf, but 16K seems like it should be enough

10MB for min debug log line size is a lot!

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we get into this branch if exceeding cyclic.limit that is 1GB by default. and I only want to print really big messages even if someone sets smaller log file size for rotation.

fmt.Fprintf(os.Stderr, "Attempt to write a large log line:\n%s\n", string(buf[:stlen]))
fmt.Fprintf(os.Stderr, "The offending line:\n%s\n", string(p[:4096]))
}

return 0, fmt.Errorf("CyclicFileWriter: input too long to write. Len = %v", len(p))
}

Expand Down