Skip to content
This repository was archived by the owner on Aug 30, 2024. It is now read-only.

Commit 4eafe01

Browse files
authored
feat: show build log timestamps in local time (#241)
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.
1 parent 32fbd7e commit 4eafe01

File tree

1 file changed

+23
-4
lines changed

1 file changed

+23
-4
lines changed

internal/cmd/rebuild.go

+23-4
Original file line numberDiff line numberDiff line change
@@ -91,47 +91,66 @@ func trailBuildLogs(ctx context.Context, client *coder.Client, envID string) err
9191
if err != nil {
9292
return err
9393
}
94+
9495
var s *spinner.Spinner
9596
for l := range logs {
9697
if l.Err != nil {
9798
return l.Err
9899
}
100+
101+
logTime := l.BuildLog.Time.Local()
102+
msg := fmt.Sprintf("%s %s", logTime.Format(time.RFC3339), l.BuildLog.Msg)
103+
99104
switch l.BuildLog.Type {
100105
case coder.BuildLogTypeStart:
101106
// the FE uses this to reset the UI
102107
// the CLI doesn't need to do anything here given that we only append to the trail
108+
103109
case coder.BuildLogTypeStage:
104-
msg := fmt.Sprintf("%s %s", l.BuildLog.Time.Format(time.RFC3339), l.BuildLog.Msg)
105110
if !isTerminal {
106111
fmt.Println(msg)
107112
continue
108113
}
114+
109115
if s != nil {
110116
s.Stop()
111117
fmt.Print("\n")
112118
}
119+
113120
s = newSpinner()
114121
s.Suffix = fmt.Sprintf(" -- %s", msg)
115122
s.FinalMSG = fmt.Sprintf("%s -- %s", check, msg)
116123
s.Start()
124+
117125
case coder.BuildLogTypeSubstage:
118126
// TODO(@cmoog) add verbose substage printing
127+
if !verbose {
128+
continue
129+
}
130+
119131
case coder.BuildLogTypeError:
120-
errMsg := color.RedString("\t%s", l.BuildLog.Msg)
121132
if !isTerminal {
122-
fmt.Println(errMsg)
133+
fmt.Println(msg)
123134
continue
124135
}
136+
125137
if s != nil {
126138
s.FinalMSG = fmt.Sprintf("%s %s", failure, strings.TrimPrefix(s.Suffix, " "))
127139
s.Stop()
140+
fmt.Print("\n")
128141
}
129-
fmt.Print(errMsg)
142+
130143
s = newSpinner()
144+
s.Suffix = color.RedString(" -- %s", msg)
145+
s.FinalMSG = color.RedString("%s -- %s", failure, msg)
146+
s.Start()
147+
131148
case coder.BuildLogTypeDone:
132149
if s != nil {
133150
s.Stop()
151+
fmt.Print("\n")
134152
}
153+
135154
return nil
136155
default:
137156
return xerrors.Errorf("unknown buildlog type: %s", l.BuildLog.Type)

0 commit comments

Comments
 (0)