-
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
fix data race on set level and formatter #374
Conversation
logger.go
Outdated
func (logger *Logger) formatter() Formatter { | ||
logger.mu.RLock() | ||
defer logger.mu.RUnlock() | ||
return logger.Formatter |
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.
You may avoid some overhead by not using defer
as it is not strictly necessary here - reading a field can not panic and logger
is not nil
because it was accessed one line above. Same for the level()
method.
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.
If you could make the small adjustment to remove the defer and ping me, I'd be happy to merge this pull request.
Thanks for contributing this improvement!
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.
@aarongreenlee I've addressed the code review comment
@aarongreenlee ping |
Thanks, @klizhentas. This all looks good to me. Can you please resolve these minor conflicts? I'll merge shortly thereafter. Thanks for this contribution. |
@klizhentas pinging to have merge conflicts resolved. Good work! |
I don't think it's actually possible to have my changeset to coexist with the master mostly because of this chunk of code that turns off locking: https://github.com/Sirupsen/logrus/blob/master/logger.go#L53 https://github.com/Sirupsen/logrus/blob/master/logger.go#L306 Moreover I think the new Lock()
SetNoLock()
Unlock() getting a deadlock. Everyones ideas on getting this altogether are appreciated. |
defer wg.Done() | ||
switch i % 4 { | ||
case 0: | ||
SetLevel(InfoLevel) |
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.
Is there an equivalent (*Logger).SetLevel
? It seems odd that this method would be at the package level but use a struct bound lock without offering the method on the struct itself.
I think it's partially fixed by #512, but However, I'm still unconvinced that we really should bother about that in the first place, given the fact the most of the loggers and hooks are IO bound. Any thoughts on the matter? Synthetic benchmarks do not really show the realistic scenarios. |
Lowercase sirupsen everywhere.
fixes #295