Skip to content

Commit bbc6f24

Browse files
committed
Address comments
1 parent d00dde9 commit bbc6f24

1 file changed

Lines changed: 13 additions & 5 deletions

File tree

sdks/go/container/tools/buffered_logging.go

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -64,13 +64,21 @@ func (b *BufferedLogger) Write(p []byte) (int, error) {
6464
b.logs = make([]string, 0, initialLogSize)
6565
}
6666
s := b.builder.String()
67-
if lastNL := strings.LastIndex(s, "\n"); lastNL != -1 {
68-
lines := strings.Split(s[:lastNL], "\n")
69-
for _, line := range lines {
70-
b.logs = append(b.logs, strings.TrimSuffix(line, "\r"))
67+
start := 0
68+
for {
69+
nl := strings.IndexByte(s[start:], '\n')
70+
if nl == -1 {
71+
break
7172
}
73+
line := s[start : start+nl]
74+
b.logs = append(b.logs, strings.TrimSuffix(line, "\r"))
75+
start += nl + 1
76+
}
77+
if start > 0 {
7278
b.builder.Reset()
73-
b.builder.WriteString(s[lastNL+1:])
79+
if start < len(s) {
80+
b.builder.WriteString(s[start:])
81+
}
7482
}
7583
if b.now().Sub(b.lastFlush) > b.flushInterval {
7684
b.FlushAtDebug(b.periodicFlushContext)

0 commit comments

Comments
 (0)