Programming with Soulcutter

Write code like you mean it

How to Turn Off Dragonfly's Default Verbose Rack-cache

It was a minor annoyance that my feature specs were incredibly verbose, filling my console with rack-cache trace debugging information like so:

1
2
3
cache: [GET /assets/logo.jpg] miss, store
cache: [GET /assets/bg-nav.jpg] miss, store
cache: [GET /assets/bg-box.jpg] miss, store

I tracked it down to the fact that Dragonfly's default configuration adds rack-cache to your middleware stack configured with verbose logging enabled.

My solution was to add a block in my Dragonfly initializer to remove that noisy rack-cache and insert my own quiet version.

config/initializers/dragonfly.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
require 'dragonfly/rails/images'

app = Dragonfly[:images]

# some storage settings here...

# shuts down verbose cache logging
if %w(development test).include? Rails.env
  Rails.application.middleware.delete(Rack::Cache)

  Rails.application.middleware.insert 0, Rack::Cache, {
    :verbose     => false, # this is set to true in dragonfly/rails/images
    :metastore   => URI.encode("file:#{Rails.root}/tmp/dragonfly/cache/meta"), # URI encoded in case of spaces
    :entitystore => URI.encode("file:#{Rails.root}/tmp/dragonfly/cache/body")
  }
end

Now my testing serenity is unperturbed by extra logging noise.

Comments