progressui: print logs for failed step as summary in plain mode

Signed-off-by: Tonis Tiigi <tonistiigi@gmail.com>
v0.9
Tonis Tiigi 2021-06-30 20:09:23 -07:00
parent 921b0de92e
commit 600d2837b5
2 changed files with 22 additions and 0 deletions

View File

@ -2,6 +2,7 @@ package progressui
import (
"bytes"
"container/ring"
"context"
"fmt"
"io"
@ -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
@ -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, "------")
}
}

View File

@ -1,6 +1,7 @@
package progressui
import (
"container/ring"
"context"
"fmt"
"io"
@ -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
@ -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 {