1

I'm trying to figure out how to quiet the very distracting Cache read: http://localhost:3000/assets/... statements in my Rails development.log, which really slow me down with all the scrolling they cause me to do (I'm on Rails 3.2).

In my development log, after the SQL statements, and reads/writes for cache fragments (which is still useful and I want to keep), there is a long list of Cache read statements for all the js, css, and images being used on the requested page. Just to show a handful:

Cache read: http://localhost:3000/assets/jquery.atwho.css?body=1
Cache read: http://localhost:3000/assets/jquery.selectric.css?body=1
Cache read: http://localhost:3000/assets/font-awesome.css?body=1
Cache read: http://localhost:3000/assets/480.css?body=1
Cache read: http://localhost:3000/assets/768.css?body=1

I'm using the quiet_assets gem as was suggested in another SO post, but that's not working on these "Cache read" statements.

Is there some simple setting I'm missing in config/environments/development.rb to not output these to the log? Thanks everyone

EDIT: Here are my development.rb settings (I included anything that might be relevant):

config.consider_all_requests_local = true

# cache store
config.action_controller.perform_caching = true
config.cache_store = :dalli_store, nil, { 
  value_max_bytes: 10485760,
  compress: true
}
config.static_cache_control = "public, max-age=2592000"

config.assets.compress = false
config.assets.debug = true
config.assets.logger = false
Community
  • 1
  • 1
DelPiero
  • 489
  • 1
  • 10
  • 21

1 Answers1

2

The "Cache read" lines are coming from the Dalli cache backend and they are shown for all accesses to the Dalli cache store. If you want to suppress this debugging line for just the accesses dealing with "assets" keys but still have others logged, you will have to monkey-patch Dalli in a Rails initializer:

# config/initializers/dalli_assets_silencer.rb:
module ActiveSupport
  module Cache
    class DalliStore

      private

      alias_method :orig_log, :log

      # silences "Cache read ..." etc debug lines for assets, but allows all others 
      def log(operation, key, options=nil)
        return if key.to_s.include?("/assets/")
        orig_log(operation, key, options)
      end

    end
  end
end

The initializer redefines the log method of Dalli store so that it actually logs the cache access only when the key does not match the "/assets/" string. If it does, the redefined log does nothing.

Matouš Borák
  • 15,606
  • 1
  • 42
  • 53
  • Brilliant, thank you so much! That quieted all the `Cache read` statements with `"/assets/"` in them. There's still a long log output of what looks like digests of some kind: `Cache read: 4930ce0c6ab3bcab1daa8f0d67791c6834742c7b` (but dozens of those). I inspected the log call, and it looks like the `operation` is `:read`, and the `key` is the digest, e.g. `4930ce0c6ab3bcab1daa8f0d67791c6834742c7b`. I don't suppose there's a way to filter these out, while leaving non-asset cache reads intact? – DelPiero May 02 '16 at 19:26
  • 1
    You can match anything to ignore using the same pattern, or, in this case, a regexp, in the `log` overridden method. Something like this, for example: `return if key.to_s.include?("/assets/") || key.to_s =~ /[0-9a-f]{30,}/` which should match asset keys and digest keys with more than 30 characters. – Matouš Borák May 02 '16 at 19:59