logtail: minor style/simplification changes

reviewable/pr187/r1
Brad Fitzpatrick 4 years ago
parent 8de67844bd
commit 8f9fa6a842

@ -169,7 +169,8 @@ func (l *logger) drainPending() (res []byte) {
entries := 0 entries := 0
var batchDone bool var batchDone bool
for buf.Len() < 1<<18 && !batchDone { const maxLen = 256 << 10
for buf.Len() < maxLen && !batchDone {
b, err := l.buffer.TryReadLine() b, err := l.buffer.TryReadLine()
if err == io.EOF { if err == io.EOF {
break break
@ -292,7 +293,7 @@ func (l *logger) upload(ctx context.Context, body []byte) (uploaded bool, err er
if resp.StatusCode != 200 { if resp.StatusCode != 200 {
uploaded = resp.StatusCode == 400 // the server saved the logs anyway uploaded = resp.StatusCode == 400 // the server saved the logs anyway
b, _ := ioutil.ReadAll(resp.Body) b, _ := ioutil.ReadAll(resp.Body)
return uploaded, fmt.Errorf("log upload of %d bytes %s failed %d: %q", len(body), compressedNote, resp.StatusCode, string(b)) return uploaded, fmt.Errorf("log upload of %d bytes %s failed %d: %q", len(body), compressedNote, resp.StatusCode, b)
} }
return true, nil return true, nil
} }
@ -402,10 +403,8 @@ func (l *logger) Write(buf []byte) (int, error) {
} else { } else {
// The log package always line-terminates logs, // The log package always line-terminates logs,
// so this is an uncommon path. // so this is an uncommon path.
bufnl := make([]byte, len(buf)+1) withNL := append(buf[:len(buf):len(buf)], '\n')
copy(bufnl, buf) l.stderr.Write(withNL)
bufnl[len(bufnl)-1] = '\n'
l.stderr.Write(bufnl)
} }
} }
b := l.encode(buf) b := l.encode(buf)

Loading…
Cancel
Save