Merge pull request #1089 from mlaventure/fix-logging-on-error

Ensure we log into logrus on command error
This commit is contained in:
Mrunal Patel 2016-10-03 09:42:46 -07:00 committed by GitHub
commit 02f8fa7863
1 changed files with 14 additions and 0 deletions

14
main.go
View File

@ -2,6 +2,7 @@ package main
import (
"fmt"
"io"
"os"
"strings"
@ -129,7 +130,20 @@ func main() {
}
return nil
}
// If the command returns an error, cli takes upon itself to print
// the error on cli.ErrWriter and exit.
// Use our own writer here to ensure the log gets sent to the right location.
cli.ErrWriter = &FatalWriter{cli.ErrWriter}
if err := app.Run(os.Args); err != nil {
fatal(err)
}
}
type FatalWriter struct {
cliErrWriter io.Writer
}
func (f *FatalWriter) Write(p []byte) (n int, err error) {
logrus.Error(string(p))
return f.cliErrWriter.Write(p)
}