Skip to content

Commit

Permalink
Add remote logger wait timeout
Browse files Browse the repository at this point in the history
  • Loading branch information
mstoykov committed Nov 25, 2020
1 parent 170eafb commit 076a7dd
Showing 1 changed file with 16 additions and 4 deletions.
20 changes: 16 additions & 4 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import (
"path/filepath"
"strings"
"sync"
"time"

"github.com/fatih/color"
"github.com/mattn/go-colorable"
Expand All @@ -54,7 +55,10 @@ var (
stderr = &consoleWriter{colorable.NewColorableStderr(), stderrTTY, outMutex, nil}
)

const defaultConfigFileName = "config.json"
const (
defaultConfigFileName = "config.json"
waitRemoteLoggerTimeout = time.Second * 5
)

//TODO: remove these global variables
//nolint:gochecknoglobals
Expand Down Expand Up @@ -205,15 +209,23 @@ func Execute() {
if c.loggerIsRemote {
fallbackLogger.WithFields(fields).Error(err)
cancel()
<-c.loggerStopped // TODO have a timeout?
c.waitRemoteLogger()
}

os.Exit(code)
}

cancel()
c.waitRemoteLogger()
}

func (c *rootCommand) waitRemoteLogger() {
if c.loggerIsRemote {
cancel()
<-c.loggerStopped // TODO have a timeout?
select {
case <-c.loggerStopped:
case <-time.After(waitRemoteLoggerTimeout):
c.fallbackLogger.Error("Remote logger didn't stop in %s", waitRemoteLoggerTimeout)
}
}
}

Expand Down

0 comments on commit 076a7dd

Please sign in to comment.