-
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
Added checks for logger not being attached to the entry type and handling gracefully #1033
base: master
Are you sure you want to change the base?
Conversation
@sinhashubham95 Can you describe the scenarios under which this would occur? And can you add some tests to ensure those scenarios are covered? |
@freeformz the thing is you are exposing the type entry as a result of which anyone can create a new variable of the same without associating it to a logger and attempt to log. |
@@ -241,6 +250,11 @@ func (entry Entry) log(level Level, msg string) { | |||
} | |||
|
|||
func (entry *Entry) fireHooks() { | |||
// add a check for logger being nil because entry is exposed | |||
if entry.Logger == nil { | |||
fmt.Fprintf(os.Stderr, "Logger not attached\n") |
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 feel like this shouldn't happen. If no logger is attached, I don't expect any output.
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 is an error scenario. So at least the logs should go to the standard error output. No error should be blindly ignored.
@freeformz any update, if everything is fine, can you go ahead and merge the pull request. |
Is this "solvable" by adding a disclaimer on the Entry godoc that says "An Entry without a Logger is basically useless and not setting Logger will cause most, if not all of Entry's methods to panic" ? I'm not personally inclined to merge this for the following reasons:
Perhaps one of the other maintainers feels differently? |
@freeformz what I think is as an API developer or basically a Utility developer, the API or Utility should be full-proof, not depending on some disclaimer, rather it should not panic in any known scenario, rather provide proper logs using which we can get to know the root cause of any issue. I will tell you a scenario that I faced just today in production. We are using a monitoring tool, but don't have the money enough to buy the support using which for any process crash, I can download the crash dump. At that point in time, I really felt panic in Go is the worst thing to happen to you, as I had basically no clue to know what caused this. In short, I strongly think the above change is required. |
@freeformz any update on this? |
No description provided.