-
-
Notifications
You must be signed in to change notification settings - Fork 263
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
Add new Rails/EagerEvaluationLogMessage
cop
#483
Conversation
e072e9c
to
b8aaa0e
Compare
CHANGELOG.md
Outdated
@@ -350,7 +351,7 @@ | |||
[@forresty]: https://github.com/forresty | |||
[@sinsoku]: https://github.com/sinsoku | |||
[@pocke]: https://github.com/pocke | |||
[@gyfis]: https:/github.com/gyfis | |||
[@gyfis]: https://github.com/gyfis |
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 like, can you open another PR for this typo fixing.
Yes, I think this would be better suited to https://github.com/rubocop/rubocop as a |
Performance cop is managed by https://github.com/rubocop/rubocop-performance :-) This is a technical note. Ruby's |
Thank you for your helpful feedback, I will make changes in the next couple days as we continue to discuss some of the details. I am wondering if it could make sense to have three enforced styles, one being (the default) "always use blocks for interpolated strings, never use blocks otherwise", one being "never use blocks", and one being "always use blocks". @koic you are correct about the difficulty of detecting any call to any subclass of On a side note, using the |
b8aaa0e
to
96f6fa4
Compare
Rails/LoggerBlock
copRails/EagerEvaluationLogMessage
cop
96f6fa4
to
57bd23a
Compare
Is it faster with blocks even for non-interpolation strings? I haven't benchmarked it, but I'm concerned it won't be faster for plain (non-interpolation) strings. So I think it will be limited if blocks are required, and
I think (maybe) something existed, but I cannot remember without investigating :-) |
I'm having trouble reading the tests (in general, looping in tests make them less clear) – do you intend to warn people when calling |
91f2653
to
4c5f7bf
Compare
@koic Today or tomorrow I am going to do some benchmarks on your idea of interpolated vs non interpolated strings, and then perhaps we can make a more informed decision. Is it worth also considering that users could be passing other things to Also, do you have any opinion on taking the default rails logger level (was |
Ok, here are my findings. I have attached two files, a performance script and the results from running it on my laptop. The script sets
It does this for both the To summarize the results:
So, I suppose there could be three takeaways from this depending on your worldview:
performance_test.rb.txt (A .txt to satisfy GH) I am happy to make changes to the PR based on the wisdom of the people involved here. |
Great! Thank you for your taking time and investigation.
I'd like to take this one. It also matches the context mentioned in the reference. |
2af8239
to
a7f57a2
Compare
Ok @koic, I think I am finished with the changes, and ready for another review. @bquorning, as per your suggestion the cop only considers |
a7f57a2
to
acb5880
Compare
acb5880
to
36635db
Compare
Thanks! |
We really want this because nobody remembers to do it, and there's a lot of I can PR this (unless you're enthusiastic about doing it |
Hello,
The Debugging Rails Applications guide recommends that blocks are passed to Rails.logger.info et. al. instead of method arguments, as there is some performance impact on generating potentially expensive log messages that do not even end up being logged depending on
config.log_level
. Since Rails changed the defaultlog_level
to:info
, this may now be more beneficial. For example,instead of
This PR adds a new cop "Rails/LoggerBlock" that detects values passed to the various log methods, such as Rails.logger.debug, and then supports autocorrecting to the block form.
This is my first time working on Rubocop, so I am looking for feedback to see if this is something that will be useful to the community, if it should be enabled by default, or if this is something that should use two enforced styles (which I did not implement,) what the cop should be called, etc. I am also unsure if this should also attempt to detect situations where users access
logger
without theRails
prefix, as it is often in scope. Indeed, usinglogger
this way could possibly be a cop in itself. Finally, there is also theLogger#add
method which I did not deal with, but I could. Lastly as I am writing this I am realizing thatActiveSupport::Logger
actually just inheritsLogger
from the Ruby standard library, so possibly this could be just a plain rubocop cop?