-
Notifications
You must be signed in to change notification settings - Fork 19
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
fix safeError & safeString for json format #20
Conversation
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.
Thanks for the PR, and thanks for including tests!
The implementation and tests look good here, I think we can improve the specific messages we log for the panics so I've provided alternatives that I think make it more clear what has gone wrong in these situations. With those changes this will be ready to merge.
json_logger.go
Outdated
@@ -68,7 +68,7 @@ func safeString(str fmt.Stringer) (s string) { | |||
if v := reflect.ValueOf(str); v.Kind() == reflect.Ptr && v.IsNil() { | |||
s = "NULL" | |||
} else { | |||
panic(panicVal) | |||
s = fmt.Sprintf("panic stringer value: %v", panicVal) |
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 think we should make it more obvious something went wrong with getting the string (or error). I think this message may not be prominent enough.
Let's change this to:
fmt.Sprintf("PANIC in String method: %v", panicVal)
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.
sure! updated.
json_logger.go
Outdated
@@ -82,7 +82,7 @@ func safeError(err error) (s interface{}) { | |||
if v := reflect.ValueOf(err); v.Kind() == reflect.Ptr && v.IsNil() { | |||
s = nil | |||
} else { | |||
panic(panicVal) | |||
s = fmt.Sprintf("panic error value: %v", panicVal) |
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.
Similar to above let's make this:
fmt.Sprintf("PANIC in Error method: %v", panicVal)
Thanks for the contribution! |
relates to #19