dup log output onto stderr to catch panics in log file

This commit is contained in:
Matt Jaffee 2018-11-19 16:15:33 -06:00
parent 65f478470f
commit 77598c2cc6
No known key found for this signature in database
GPG key ID: 08A3DFFF987B11BF

View file

@ -176,14 +176,18 @@ func (m *Command) Wait() error {
// setupLogger sets up the logger based on the configuration.
func (m *Command) setupLogger() error {
var err error
if m.Config.LogPath == "" {
m.logOutput = m.Stderr
} else {
m.logOutput, err = os.OpenFile(m.Config.LogPath, os.O_RDWR|os.O_CREATE|os.O_APPEND, 0600)
f, err := os.OpenFile(m.Config.LogPath, os.O_RDWR|os.O_CREATE|os.O_APPEND, 0600)
if err != nil {
return errors.Wrap(err, "opening file")
}
m.logOutput = f
err = syscall.Dup2(int(f.Fd()), int(os.Stderr.Fd()))
if err != nil {
return errors.Wrap(err, "dup2ing stderr onto logfile")
}
}
if m.Config.Verbose {