From 48a10f1c5c79e70e8c5133d82e132b9526e15489 Mon Sep 17 00:00:00 2001 From: Kenfe-Mickael Laventure Date: Thu, 29 Sep 2016 14:43:50 -0700 Subject: [PATCH] Ensure we log into logrus on command error `urfave/cli` now takes upon itself to log the error returned by the command action directly. This means that by default the `--log` option was ignored upon error. This commit ensure that `urfave/cli.ErrWriter` will use logrus Signed-off-by: Kenfe-Mickael Laventure --- main.go | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/main.go b/main.go index 540656578d7..ab6e0129d93 100644 --- a/main.go +++ b/main.go @@ -129,7 +129,19 @@ 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{} if err := app.Run(os.Args); err != nil { fatal(err) } } + +type FatalWriter struct { +} + +func (FatalWriter) Write(p []byte) (n int, err error) { + logrus.Error(string(p)) + return len(p), nil +}