add a hook on fatal/panic to ensure we're logging to stderr as well (#879)

This commit is contained in:
Thibault "bui" Koechlin 2021-08-05 08:50:08 +02:00 committed by GitHub
parent fc7369c4ea
commit 2a6369658a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -20,6 +20,7 @@ import (
"github.com/pkg/errors"
log "github.com/sirupsen/logrus"
"github.com/sirupsen/logrus/hooks/writer"
"gopkg.in/tomb.v2"
)
@ -241,6 +242,13 @@ func main() {
cwversion.Show()
os.Exit(0)
}
log.AddHook(&writer.Hook{ // Send logs with level higher than warning to stderr
Writer: os.Stderr,
LogLevels: []log.Level{
log.PanicLevel,
log.FatalLevel,
},
})
cConfig, err = csconfig.NewConfig(flags.ConfigFile, flags.DisableAgent, flags.DisableAPI)
if err != nil {