-
Notifications
You must be signed in to change notification settings - Fork 21.4k
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 Issue #2639: "Served asset log messages are pretty annoying!" by adding config variable #3795
Conversation
… = false' in an environment config file
I did some benchmarking. There seems to be a small performance boost from the commit, since it causes Rack to use the Rails logger less frequently. This gist (https://gist.github.com/1404199) includes a file for the benchmarking code and files for sample output both with and without the config variable In each benchmark report, the first and third lines use before_dispatch(env) as it was before my commit, and the second and fourth lines use before_dispatch(env) (renamed before_dispatch_modified(env) here) from my commit. I repeat each, in alternating order, to help account for normal benchmarking fluctuations. If you include Without the config line specified, the conditional that I added immediately evaluates to true in every case. In the benchmarking reports, sometimes the before_dispatch(env) is faster, sometimes before_dispatch_modified(env) is.
With the config line
So there seems to be a side benefit of a performance gain of a few ten-thousandths of a second for each request. |
info "\n\nStarted #{request.request_method} \"#{path}\" " \ | ||
"for #{request.ip} at #{Time.now.to_default_s}" | ||
# If config.assets.logger is set to false, only log non-assets related requests | ||
if ((Rails.application.config.assets.logger != false) || |
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 should not use Rails.application here, please see how it's done in case of other similar options: https://github.com/ciscoriordan/rails/blob/4928434455c9a89197fda106534f57f6b319184c/railties/lib/rails/application.rb#L121
/cc @josevalim
can you send a PR for master branch instead of 3-1-stable? |
Can we PLEASE get something like this in before 3.2 final? |
I don't think we should mute both loggers, just one. That said, +1 for config.assets.logger but besides setting it to false, we could also configure sprockets logger through it and therefore use the same logger as Rails, but with increased severity. In other words, I am fine with changes in sprockets/railties (and they could be improved) but I don't think we should change rails/rack/logger. Thanks. |
How do we suppress the request log messages without changing rails/rack/logger? The purpose here is to get rid of ALL log messages related to assets. Having these in the log makes it much less useful for development. |
We are not special casing the rails logger middleware to get rid of it. As I said, I will gladly accept a patch that allows you to turn off sprockets logger, but we won t special case the middleware. |
Someone please submit a new pull request, because I think the original author won't. |
+1 to @electrum: How do we suppress the request log messages without changing rails/rack/logger? I agree with @josevalim that special casing the logger middleware, but in the meantime, it would be great if we could get rid of logging the requests that are served by assets. |
@josevalim see #4512 |
@josevalim If the change is not made in rails/rack/logger then the only other place it can be made is https://github.com/rails/rails/blob/master/activesupport/lib/active_support/tagged_logging.rb#L29 ? In that case if the user sets a custom logger, the log file will again contain the requests. So IMO the logical place to change it is rack logger since it will work for all loggers. Correct me If I'm wrong :) |
Let me rephrase: Rails won't special case any of the loggers or logger related middlewares to not log specific routes. If you want, you can inherit from the Rails::Rack::Logger in your app and special case it. Meanwhile, to be a bit less verbose, Rails added an option to change Sprockets logger, so you can set it to a higher level like warn/fatal. |
this is really unfortunate. we should not be required to use monkey patches like this: https://gist.github.com/2036895 it's not uncommon, in real apps, to want to shut the logger up for a bit. |
er. should not be... |
The current state of this is terrible. You should not have to jump through hoops to make the logger actually useful. 99% of the time you don't want your development logs filled up with noise from the assets being requested. The rails server log is functionally broken as it stands. If you want to maintain the purity of the logger, then maybe it can be monkey patched within the development environment configuration. |
@MarcoPeraza is absolutely right. Whatever happened to "convention over configuration"?! The cleanest solution I can find out there is the @josevalim, your comment above has been linked to at least twice, by @guilleiguaran here and here as "details about why we won't silent the request logs", but that's very misleading, because your comment doesn't cover why this functionality won't be implemented at all; it simply says that it won't be. By "you can inherit from the Rails::Rack::Logger in your app and special case it", you seem to be suggesting that every single Rails developer who doesn't want spam in their development log should become a Rack specialist and reinvent the same wheel?! Maybe that wasn't the message you intended, but that's how it comes across. I see that sprockets will log more silently in Rails 4.0. That's great, but what about ActionPack? To be clear, I am not necessarily disagreeing with your decision not to make Rails special-case middleware. But given the number of developers who have been bitten by this, I am strongly disagreeing with how this is being handled in terms of (a) finding an alternative user-friendly solution, and (b) communication and documentation of that solution. When a solution based on monkey-patching receives over 240 up-votes on StackOverflow then that is a sure sign that something has gone badly wrong. |
@aspiers thank you for the words, this is as far as you can get from the initial Rails spirit IMO |
so did this happen on master (re #4512) or not happen? |
I think this is precisely why Apache (and others) have a separate log for the mundane stuff (requests) vs. errors. Maybe that would be a better solution for an issue like this? |
Addresses issue #2639 (#2639) -- there are many assets related log messages and no config variable to hide them. Example log lines:
With these commits, both asset related logger messages (Sprockets and Rack) can be hidden with a config variable. By default the messages still appear.
To hide the messages, add this line to e.g. application.rb:
config.assets.logger = false
Note: This is a replacement for #3741 (closed), squashed into one commit and no longer hiding the messages by default.