-
Notifications
You must be signed in to change notification settings - Fork 2.3k
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
Error value in log.Fields disappears when using JSON formatter #137
Comments
I ran into the same issue. From what I can tell the While the I think it makes sense to do the same thing in the |
I've got a pull request out for this issue doing something a little different from the text formatter -- would be great to know if that solution meets your needs as well. Right now my workaround is using a hook to add the error message, because sometimes a custom error has extra fields that are correctly picked up by |
Hi there, just wondering what version of go this was an issue one? In golang 1.6 @rsterbin's original issue does not seem to happen:
This is relevant because one thing we would like to do is return custom errors that implement MarshalJSON() as well as Error(), so that they can be treated like plain old At the moment this particular patch prevents this. If we have a type that implements Error() then the current logrus code seems to see it as an error type and call Error() on it, which stringify's it. Example: package main
import log "github.com/Sirupsen/logrus"
type ErrorFields map[string]interface{}
func (e *ErrorFields) MarshalJSON() ([]byte, error) {
return []byte("using the MarshalJSON() call"), nil
}
func (e *ErrorFields) Error() string {
return "using the Error() call"
}
func main() {
err := &ErrorFields{}
log.SetFormatter(&log.JSONFormatter{})
log.WithFields(log.Fields{
"whatever": err,
}).Info("Logging with json")
} |
Nevermind my previous comment, I realized it doesn't quite match what @rsterbin posted and only works because of the type I am using. Turns out it's because golang/go#10748 is relevant and golang/go#5161, if actually done, could help here. |
Errors included in a logrus.Entry are not formatted correctly. This is caused by sirupsen/logrus#137
When passing an error as a field and using the JSON formatter, the error message is omitted:
Results:
The text was updated successfully, but these errors were encountered: