Eliot Sykes

Debug Rails Faster with Quiet Assets & Quieter Logs

You may find Rails’ default logging obstructs your debugging efforts when it floods the server output with waves of asset requests. Bypass this extra logging and streamline your debugging workflow by installing the Quiet Assets gem.

When running your Rails app in development, do you see a lot of lines output from the server process like this?

Started GET "/assets/...?body=1" for ::1 at 2015-09-02 12:19:27 +0100

These lines are logging requests for assets (such as javascript and stylesheet files). If you have 10 asset files, its not uncommon to find 10+ lines like the above in your log output for every 1 request for a controller action.

Between each of the asset request log lines, there might be 2 blank lines. The combined effect of all this logging is to bury useful controller action log lines by pushing them upward off the top of the terminal.

Burying the controller action requests in favor of asset requests is not usually helpful. The asset requests don’t contain interesting information unless you’re debugging an asset pipeline issue. The asset requests can get in the way of most day-to-day debugging, requiring you to scroll up to find the last controller action request in your logs. For newer developers this can be a problem as they may not realize that there is more useful data logged than asset requests alone.

Before installing the Quiet Assets gem on one particular Rails app, I saw 100+ log lines (including blank lines) for every 3 controller action requests. After installing Quiet Assets there is now about 10 lines of logging for every 3 controller requests. Reading this application’s server logs has become a more straightforward, scroll-free experience on a small screen.

Add the following line to your Gemfile to tell Bundler to use Quiet Assets in your project’s development environment:

gem 'quiet_assets', group: :development

At the command line, get Bundler to install the Quiet Assets gem:

bundle install

Once bundler finishes installing the gem, run your server and watch the output. Visit a few pages in your browser. You should notice the logging output from the server is reduced, with no logging from the assets.

In the future, say when debugging an asset pipeline issue, you can temporarily set config.quiet_assets to false in your development environment to restore asset logging:

# File: config/environments/development.rb

# To re-enable asset logging:
config.quiet_assets = false

By installing the Quiet Assets gem you will hopefully make debugging your Rails apps a little more pleasant.

ES ·

Grow Your Rails Expertise Faster