From 4c1082a50d30b1409a24edd2dc70171c66b8f5e2 Mon Sep 17 00:00:00 2001 From: Jonathan Yu Date: Thu, 11 Feb 2021 18:22:30 -0800 Subject: [PATCH] feat: show build log timestamps in local time The server-sent ISO8601 timestamps are not necessarily in the user's preferred timezone. This change uses time.Local() to get the time in the user's local time according to their system settings. --- internal/cmd/rebuild.go | 27 +++++++++++++++++++++++---- 1 file changed, 23 insertions(+), 4 deletions(-) diff --git a/internal/cmd/rebuild.go b/internal/cmd/rebuild.go index abdd243c..1eff6e08 100644 --- a/internal/cmd/rebuild.go +++ b/internal/cmd/rebuild.go @@ -91,47 +91,66 @@ func trailBuildLogs(ctx context.Context, client *coder.Client, envID string) err if err != nil { return err } + var s *spinner.Spinner for l := range logs { if l.Err != nil { return l.Err } + + logTime := l.BuildLog.Time.Local() + msg := fmt.Sprintf("%s %s", logTime.Format(time.RFC3339), l.BuildLog.Msg) + switch l.BuildLog.Type { case coder.BuildLogTypeStart: // the FE uses this to reset the UI // the CLI doesn't need to do anything here given that we only append to the trail + case coder.BuildLogTypeStage: - msg := fmt.Sprintf("%s %s", l.BuildLog.Time.Format(time.RFC3339), l.BuildLog.Msg) if !isTerminal { fmt.Println(msg) continue } + if s != nil { s.Stop() fmt.Print("\n") } + s = newSpinner() s.Suffix = fmt.Sprintf(" -- %s", msg) s.FinalMSG = fmt.Sprintf("%s -- %s", check, msg) s.Start() + case coder.BuildLogTypeSubstage: // TODO(@cmoog) add verbose substage printing + if !verbose { + continue + } + case coder.BuildLogTypeError: - errMsg := color.RedString("\t%s", l.BuildLog.Msg) if !isTerminal { - fmt.Println(errMsg) + fmt.Println(msg) continue } + if s != nil { s.FinalMSG = fmt.Sprintf("%s %s", failure, strings.TrimPrefix(s.Suffix, " ")) s.Stop() + fmt.Print("\n") } - fmt.Print(errMsg) + s = newSpinner() + s.Suffix = color.RedString(" -- %s", msg) + s.FinalMSG = color.RedString("%s -- %s", failure, msg) + s.Start() + case coder.BuildLogTypeDone: if s != nil { s.Stop() + fmt.Print("\n") } + return nil default: return xerrors.Errorf("unknown buildlog type: %s", l.BuildLog.Type)