Skip to content

Commit c8caef7

Browse files
author
Florian
committed
Stops StartWait at log.Fatal
1 parent 0fda603 commit c8caef7

2 files changed

Lines changed: 41 additions & 7 deletions

File tree

pkg/util/log/loading_text.go

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,11 @@ type loadingText struct {
1414
Stream io.Writer
1515
Message string
1616

17-
startTimestamp int64
18-
loadingRune int
19-
isShown bool
20-
stopChan chan bool
17+
startTimestamp int64
18+
loadingRune int
19+
isShown bool
20+
stopChan chan bool
21+
stopConfirmedChan chan bool
2122
}
2223

2324
func (l *loadingText) Start() {
@@ -27,13 +28,17 @@ func (l *loadingText) Start() {
2728
if l.stopChan == nil {
2829
l.stopChan = make(chan bool)
2930
}
31+
if l.stopConfirmedChan == nil {
32+
l.stopConfirmedChan = make(chan bool)
33+
}
3034

3135
go func() {
3236
l.render()
3337

3438
for {
3539
select {
3640
case <-l.stopChan:
41+
l.stopConfirmedChan <- true
3742
return
3843
case <-time.After(waitInterval):
3944
l.render()
@@ -82,6 +87,7 @@ func (l *loadingText) render() {
8287

8388
func (l *loadingText) Stop() {
8489
l.stopChan <- true
90+
<-l.stopConfirmedChan
8591
l.Stream.Write([]byte("\r"))
8692

8793
messageLength := len(l.Message) + 20

pkg/util/log/stdout_logger.go

Lines changed: 31 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ func (s *stdoutLogger) writeMessage(fnType logFunctionType, message string) {
9191

9292
fnInformation.stream.Write([]byte(message))
9393

94-
if s.loadingText != nil {
94+
if s.loadingText != nil && fnType != fatalFn {
9595
s.loadingText.Start()
9696
}
9797
}
@@ -244,7 +244,19 @@ func (s *stdoutLogger) Fatal(args ...interface{}) {
244244
s.logMutex.Lock()
245245
defer s.logMutex.Unlock()
246246

247-
s.writeMessage(fatalFn, fmt.Sprintln(args...))
247+
if s.loadingText != nil {
248+
s.loadingText.Stop()
249+
s.loadingText = nil
250+
}
251+
252+
fnInformation := fnTypeInformationMap[fatalFn]
253+
254+
ct.Foreground(fnInformation.color, false)
255+
fnInformation.stream.Write([]byte(fnInformation.tag))
256+
257+
ct.ResetColor()
258+
fnInformation.stream.Write([]byte(fmt.Sprintln(args...)))
259+
248260
s.writeMessageToFileLogger(fatalFn, args...)
249261

250262
if s.fileLogger == nil {
@@ -256,7 +268,18 @@ func (s *stdoutLogger) Fatalf(format string, args ...interface{}) {
256268
s.logMutex.Lock()
257269
defer s.logMutex.Unlock()
258270

259-
s.writeMessage(fatalFn, fmt.Sprintf(format, args...)+"\n")
271+
if s.loadingText != nil {
272+
s.loadingText.Stop()
273+
s.loadingText = nil
274+
}
275+
276+
fnInformation := fnTypeInformationMap[fatalFn]
277+
278+
ct.Foreground(fnInformation.color, false)
279+
fnInformation.stream.Write([]byte(fnInformation.tag))
280+
281+
ct.ResetColor()
282+
fnInformation.stream.Write([]byte(fmt.Sprintf(format, args...)))
260283
s.writeMessageToFileLoggerf(fatalFn, format, args...)
261284

262285
if s.fileLogger == nil {
@@ -268,6 +291,11 @@ func (s *stdoutLogger) Panic(args ...interface{}) {
268291
s.logMutex.Lock()
269292
defer s.logMutex.Unlock()
270293

294+
if s.loadingText != nil {
295+
s.loadingText.Stop()
296+
s.loadingText = nil
297+
}
298+
271299
s.writeMessage(panicFn, fmt.Sprintln(args...))
272300
s.writeMessageToFileLogger(panicFn, args...)
273301

0 commit comments

Comments
 (0)