@@ -188,6 +188,9 @@ const similarTraceThreshold = 8
188188// similarUsrMsgThreshold is the no. of similar user msgs to report before suppressing.
189189const similarUsrMsgThreshold = 3
190190
191+ // charsPerLine is max no. of characters per log line.
192+ const charsPerLine = 4500
193+
191194// spamMsgThreshold is the min. no. of spammy msgs to report.
192195var spammsgThreshold = [NONE + 1 ]uint32 {
193196 VVERBOSE : 256 >> 1 , // 128
@@ -435,15 +438,37 @@ func (l *simpleLogger) Stack(at int, msg string, scratch []byte) {
435438 }
436439 // byt2str accepted proposal: github.com/golang/go/issues/19367
437440 // previous discussion: github.com/golang/go/issues/25484
438- l .emitStack (at , appendix , msg , unsafe .String (& scratch [0 ], n ))
441+ trace := unsafe .String (& scratch [0 ], n )
442+ l .emitStack (at , appendix , msg , trace )
439443}
440444
441- func (l * simpleLogger ) msgstr (lvl LogLevel , f string , args ... any ) string {
442- msg := fmt .Sprintf (f , args ... )
443- if len (l .tag ) > 0 {
444- msg = l .tag + msg
445+ func (l * simpleLogger ) msgstr (lvl LogLevel , f string , args ... any ) (msg string ) {
446+ level := lvl .s ()
447+
448+ if len (f ) <= 0 {
449+ return level + l .tag + "<empty>"
450+ }
451+ if len (args ) <= 0 {
452+ return level + l .tag + f
453+ }
454+ msg = fmt .Sprintf (f , args ... )
455+ if len (msg ) <= charsPerLine {
456+ return level + l .tag + msg
457+ }
458+
459+ var s strings.Builder
460+ for i := 0 ; i < len (msg ); i += charsPerLine {
461+ if i > 0 {
462+ s .WriteByte ('\n' )
463+ }
464+ s .WriteString (level )
465+ if len (l .tag ) > 0 {
466+ s .WriteString (l .tag )
467+ }
468+ end := min (i + charsPerLine , len (msg ))
469+ s .WriteString (msg [i :end ])
445470 }
446- return lvl . s () + msg
471+ return s . String ()
447472}
448473
449474// out logs to stdout and pushes msg into ring buffer.
0 commit comments