Steve Klabnik changelog.com/posts

Quiet Assets: Silence Asset Pipeline Messages

The Rails 3 Asset Pipeline is super powerful, but it has one thing about it that’s truly annoying: tons of logger output in development mode. Here’s a simple Rails app’s log output when hitting an index page:

Started GET "/" for 127.0.0.1 at 2012-04-16 13:48:27 -0400
Processing by ArticlesController#index as HTML
  Article Load (0.2ms)  SELECT "articles".* FROM "articles" 
  Rendered articles/index.html.erb within layouts/application (2.3ms)
Completed 200 OK in 11ms (Views: 9.5ms | ActiveRecord: 0.2ms)

Started GET "/assets/authors.css?body=1" for 127.0.0.1 at 2012-04-16 13:48:27 -0400
 Served asset /authors.css - 304 Not Modified (0ms)
 [2012-04-16 13:48:27] WARN  Could not determine content-length of response body. Set content-length of the response or set Response#chunked = true

Started GET "/assets/tags.css?body=1" for 127.0.0.1 at 2012-04-16 13:48:27 -0400
Served asset /tags.css - 304 Not Modified (0ms)
[2012-04-16 13:48:27] WARN  Could not determine content-length of response body. Set content-length of the response or set Response#chunked = true

 Started GET "/assets/jquery.js?body=1" for 127.0.0.1 at 2012-04-16 13:48:27 -0400
 Served asset /jquery.js - 304 Not Modified (0ms)
 [2012-04-16 13:48:27] WARN  Could not determine content-length of response body. Set content-length of the response or set Response#chunked = true


Started GET "/assets/comments.js?body=1" for 127.0.0.1 at 2012-04-16 13:48:27 -0400
Served asset /comments.js - 304 Not Modified (0ms)
[2012-04-16 13:48:27] WARN  Could not determine content-length of response body. Set content-length of the response or set Response#chunked = true


Started GET "/assets/tags.js?body=1" for 127.0.0.1 at 2012-04-16 13:48:27 -0400
Served asset /tags.js - 304 Not Modified (0ms)
[2012-04-16 13:48:27] WARN  Could not determine content-length of response body. Set content-length of the response or set Response#chunked = true


Started GET "/assets/application.js?body=1" for 127.0.0.1 at 2012-04-16 13:48:27 -0400
Served asset /application.js - 304 Not Modified (0ms)
[2012-04-16 13:48:27] WARN  Could not determine content-length of response body. Set content-length of the response or set Response#chunked = true

Seriously, I chopped about half of that out. Really, really annoying.

Enter quiet_assets. This little gem makes all of this junk go away. To install it, just add

gem 'quiet_assets', :group => :development

to your Gemfile, bundle, and breathe. Now, it just looks like this:

Started GET "/" for 127.0.0.1 at 2012-04-16 13:51:54 -0400
Processing by ArticlesController#index as HTML
  Article Load (0.1ms)  SELECT "articles".* FROM "articles" 
  Rendered articles/index.html.erb within layouts/application (2.7ms)
 Completed 200 OK in 115ms (Views: 65.2ms | ActiveRecord: 1.8ms)
[2012-04-16 13:51:54] WARN  Could not determine content-length of response body. Set content-length of the response or set Response#chunked = true
[2012-04-16 13:51:54] WARN  Could not determine content-length of response body. Set content-length of the response or set Response#chunked = true

Much nicer. I can actually tell what’s going on!

Check it out on GitHub.


Discussion

Sign in or Join to comment or subscribe

Player art
  0:00 / 0:00