Skip to content

Commit

Permalink
Merge pull request #2214 from tonistiigi/plain-error-logs
Browse files Browse the repository at this point in the history
progressui: print logs for failed step as summary in plain mode
  • Loading branch information
AkihiroSuda committed Jul 1, 2021
2 parents 8d70a9e + 600d283 commit edc28d1
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
12 changes: 12 additions & 0 deletions util/progress/progressui/display.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package progressui

import (
"bytes"
"container/ring"
"context"
"fmt"
"io"
Expand Down Expand Up @@ -130,6 +131,7 @@ type vertex struct {
logs [][]byte
logsPartial bool
logsOffset int
logsBuffer *ring.Ring // stores last logs to print them on error
prev *client.Vertex
events []string
lastBlockTime *time.Time
Expand Down Expand Up @@ -295,10 +297,20 @@ func (t *trace) printErrorLogs(f io.Writer) {
if v.Error != "" && !strings.HasSuffix(v.Error, context.Canceled.Error()) {
fmt.Fprintln(f, "------")
fmt.Fprintf(f, " > %s:\n", v.Name)
// tty keeps original logs
for _, l := range v.logs {
f.Write(l)
fmt.Fprintln(f)
}
// printer keeps last logs buffer
if v.logsBuffer != nil {
for i := 0; i < v.logsBuffer.Len(); i++ {
if v.logsBuffer.Value != nil {
fmt.Fprintln(f, string(v.logsBuffer.Value.([]byte)))
}
v.logsBuffer = v.logsBuffer.Next()
}
}
fmt.Fprintln(f, "------")
}
}
Expand Down
10 changes: 10 additions & 0 deletions util/progress/progressui/printer.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package progressui

import (
"container/ring"
"context"
"fmt"
"io"
Expand All @@ -18,6 +19,8 @@ const maxDelay = 10 * time.Second
const minTimeDelta = 5 * time.Second
const minProgressDelta = 0.05 // %

const logsBufferSize = 10

type lastStatus struct {
Current int64
Timestamp time.Time
Expand Down Expand Up @@ -130,6 +133,13 @@ func (p *textMux) printVtx(t *trace, dgst digest.Digest) {
if i != len(v.logs)-1 || !v.logsPartial {
fmt.Fprintln(p.w, "")
}
if v.logsBuffer == nil {
v.logsBuffer = ring.New(logsBufferSize)
}
v.logsBuffer.Value = l
if !v.logsPartial {
v.logsBuffer = v.logsBuffer.Next()
}
}

if len(v.logs) > 0 {
Expand Down

0 comments on commit edc28d1

Please sign in to comment.