Skip to content

Commit 247be51

Browse files
author
anahan
committed
Interpret EOF as line end in log data_listener
1 parent bfa7457 commit 247be51

File tree

5 files changed

+9
-5
lines changed

5 files changed

+9
-5
lines changed

internal/applog/data_listener.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ func (l *DataListener) handleConnection(conn net.Conn) {
4141
defer l.rPool.Put(reader)
4242

4343
for {
44-
buf, err := line.ReadOne(reader)
44+
buf, err := line.ReadOne(reader, true)
4545
if err != nil {
4646
if err != io.EOF {
4747
l.errorChan <- err

pkg/line/read.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,17 @@ import (
66
"io"
77
)
88

9-
func ReadOne(r *bufio.Reader) ([]byte, error) {
9+
func ReadOne(r *bufio.Reader, retBufOnEOF bool) ([]byte, error) {
1010
skip := false
1111

1212
for {
1313
line, err := r.ReadSlice('\n')
1414

1515
if errors.Is(err, io.EOF) {
16+
if retBufOnEOF {
17+
return line, nil
18+
}
19+
1620
return nil, err
1721
}
1822

pkg/line/read_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import (
1212
func tf(t *testing.T, in string, out []byte, expectedErr error) {
1313
r := bufio.NewReaderSize(bytes.NewBufferString(in), 16)
1414

15-
line, err := ReadOne(r)
15+
line, err := ReadOne(r, false)
1616
assert.Equal(t, expectedErr, err)
1717
assert.Equal(t, out, line)
1818
}

pkg/phpfpm/errlog_parser.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ var errLogEntryRegexp = regexp.MustCompile(`^\[([^]]+)]\s+(ALERT|ERROR|WARNING|N
3030

3131
func (p *ErrLogParser) ParseOne(r *bufio.Reader) (ErrLogEntry, error) {
3232
result := ErrLogEntry{}
33-
buf, err := line.ReadOne(r)
33+
buf, err := line.ReadOne(r, false)
3434
if err != nil {
3535
return result, err
3636
}

pkg/phpfpm/slowlog_parser.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ func (slp *SlowlogParser) Parse(ctx context.Context, r io.Reader, out chan Slowl
135135
bufioReader := bufio.NewReader(r)
136136

137137
for {
138-
buf, err := line.ReadOne(bufioReader)
138+
buf, err := line.ReadOne(bufioReader, false)
139139
if err != nil {
140140
errCh <- err
141141

0 commit comments

Comments
 (0)