rails development log filled with GET requests, want to see only database requests
development-environment, logging, ruby-on-rails, ruby-on-rails-3, ruby-on-rails-3.2
Solution
UPDATE: Since I wrote the below, someone has made a gem that does the same thing. Probably a better approach. https://rubygems.org/gems/quiet_assets
Put this into `config/initializers/quiet_assets.rb` and restart your dev server.
#
#
# Silence the log file if it's loading up an asset. That is, get rid of
# the following types of entries in the development log:
#
# Started GET "/assets/application.css?body=1" for 127.0.0.1 at 2012-03-05 11:52:18 -0800
# Served asset /application.css - 200 OK (5ms)
#
Rails.application.assets.logger = Logger.new('/dev/null')
Rails::Rack::Logger.class_eval do
def call_with_quiet_assets(env)
previous_level = Rails.logger.level
Rails.logger.level = Logger::ERROR if env['PATH_INFO'].index("/assets/") == 0
call_without_quiet_assets(env).tap do
Rails.logger.level = previous_level
end
end
alias_method_chain :call, :quiet_assets
end
Problem
My rails development log has an insane amount of these kinds of lines: ``` Started GET "/assets/services.css?body=1" for 127.0.0.1 at 2012-11-26 02:27:49 -0800 Served asset /services.css - 304 Not Modified (0ms) [2012-11-26 02:27:49] WARN Could not determine content-length of response body. Set content-length of the response or set Response#chunked = true ``` I guess I need to figure out how to have rails determine the content-length or set response.chunked somewhere (not sure what that is exactly) to avoid that last line. But still, the vast majority of time I have to waste my time searching through these to find the database requests like this: ``` Started GET "/points" for 127.0.0.1 at 2012-11-26 02:27:54 -0800 Processing by PointsController#index as HTML User Load (0.3ms) SELECT "users".* FROM "users" WHERE "users"."id" = 1 LIMIT 1 PointsLog Load (0.1ms) SELECT "points_logs".* FROM "points_logs" WHERE "points_logs"."user_id" = 1 Rendered points/index.html.erb within layouts/application (5.4ms) Completed 200 OK in 43ms (Views: 40.0ms | ActiveRecord: 0.8ms) ``` Is there a separate log for these types of requests I can look at? Is there a way to temporarily, or even permanently, suppress the log entries beginning with "Served asset"? Or just don't log serving assets?