-
Notifications
You must be signed in to change notification settings - Fork 2.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Ensure we log into logrus on command error #1089
Conversation
ba87799
to
48a10f1
Compare
So, I've gotta go for the day, but I'll look at it tomorrow, if someone has an idea on how to handle both, let me know :) |
48a10f1
to
7cf95f3
Compare
I just realized, since this is only called on error from the cli, I can just also output it to stderr :) |
cb9e9c7
to
de4dd42
Compare
// the error on cli.ErrWriter and exit. | ||
// Use our own writer here to ensure the log gets sent to the right location. | ||
originalCliErrWriter = cli.ErrWriter | ||
cli.ErrWriter = &FatalWriter{} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: instead of the global originalCliErrWriter
add it to a field on FatalWriter
de4dd42
to
924f958
Compare
updated On Fri, Sep 30, 2016 at 9:32 AM Michael Crosby notifications@github.com
|
msg := string(p) | ||
logrus.Error(msg) | ||
fmt.Fprint(f.cliErrWriter, msg) | ||
return len(p), nil |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should just be f.cliErrWriter.Write(p)
IMO. Why go through Fprintf
(which in languages like C would be punished with arbitrary code execution 😉).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In other words just make the code:
logrus.Error(string(p))
return f.cliErrWriter.Write(p)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yep, totally right. Update incoming, thanks.
924f958
to
ed9767b
Compare
|
||
func (f *FatalWriter) Write(p []byte) (n int, err error) { | ||
logrus.Error(string(p)) | ||
f.cliErrWriter.Write(p) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are you intentionally ignoring the error / actual number of bytes written?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was initially because logrus doesn't return it. But I guess it makes sense to return the value from the cli writer
`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 <mickael.laventure@gmail.com>
ed9767b
to
294d24f
Compare
urfave/cli
now takes upon itself to log the error returned by thecommand action directly. This means that by default the
--log
optionwas ignored upon error.
This commit ensure that
urfave/cli.ErrWriter
will use logrusSigned-off-by: Kenfe-Mickael Laventure mickael.laventure@gmail.com