Skip to content
This repository has been archived by the owner on Feb 27, 2023. It is now read-only.

Fix to remove empty line in log #87

Merged
merged 1 commit into from
Aug 31, 2018
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
30 changes: 24 additions & 6 deletions infrastructure/docker/log.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,22 @@ type buildLogger struct {
}

func (l *buildLogger) ReadLine() (*LogLine, error) {
line, _, err := l.reader.ReadLine()
s := &struct {
Stream string `json:"stream"`
}{}
json.NewDecoder(bytes.NewReader(line)).Decode(s)
return &LogLine{Timestamp: clock.Now(), Message: []byte(s.Stream)}, err
for {
line, _, readErr := l.reader.ReadLine()
msg := extractMessage(line)
if readErr == io.EOF {
return &LogLine{Timestamp: clock.Now(), Message: msg}, readErr
}
if readErr != nil {
return nil, errors.WithStack(readErr)
}

if len(msg) == 0 {
continue
}

return &LogLine{Timestamp: clock.Now(), Message: msg}, readErr
}
}

type runLogger struct {
Expand All @@ -55,6 +65,14 @@ func (l *runLogger) ReadLine() (*LogLine, error) {
}
}

func extractMessage(line []byte) []byte {
s := &struct {
Stream string `json:"stream"`
}{}
json.NewDecoder(bytes.NewReader(line)).Decode(s)
return []byte(s.Stream)
}

func trimPrefix(line []byte) ([]byte, error) {
if len(line) < 8 {
return []byte{}, nil
Expand Down