Skip to content

Commit

Permalink
Ensure we log into logrus on command error
Browse files Browse the repository at this point in the history
`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 <[email protected]>
  • Loading branch information
mlaventure committed Sep 29, 2016
1 parent 3597b7b commit 48a10f1
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

0 comments on commit 48a10f1

Please sign in to comment.