-
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
improved: move level check from entry to logger and bail out faster #154
Conversation
@@ -110,6 +110,10 @@ func (entry *Entry) Debug(args ...interface{}) { | |||
} | |||
} | |||
|
|||
func (entry *Entry) debug(args ...interface{}) { | |||
entry.log(DebugLevel, fmt.Sprint(args...)) | |||
} |
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.
Aren't these methods only added to avoid another integer comparison?
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.
Yeah. I could remove them and call the original (publicly exported) ones. What do you think?
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.
Yeah, I don't think this extra code is necessary but I'm happy to accept the other part of the patch. Please rebase when you do that as well so it's just one commit. Thanks!
@sirupsen done. Let me know if its good now |
improved: move level check from entry to logger and bail out faster
Thank you! It'll be in 0.7.1 |
You should re-run the benchmarks :) I'll happily accept other performance patches like this that don't break the API. |
Thanks! |
improved: move level check from entry to logger and bail out faster
improved: move level check from entry to logger and bail out faster
Hi there.
Thank you for logrus, it's a wonderful logger.
I was benchmarking loggers, as mentioned in https://github.com/imkira/go-loggers-bench
and I found I could make logrus bail-out faster (but more importantly, lesser allocations) when the baseline log-level is higher than the level being logged.
This is a modest attempt to improve it.
I didn't do it in this PR, but I also tried to do the same with WithFields, but given the current API it is very difficult to do it.
My idea was to invert
log.WithFields(...).Info(...)
and allow something like:
log.Info(...).WithFields(...)
or alternatively something like
log.WithLevel(Info).WithFields(...).Log(...)
Using this kind of API it would be possible to return "blackhole" entries/loggers when the level does not satisfy the level condition.
What do you think of it?