为我的所有资产在 Rails development.log 中屏蔽 "Cache read" 语句

Silencing "Cache read" statements in Rails development.log for all my assets

我想弄清楚如何让我的 Rails development.log 中那些非常令人分心的 Cache read: http://localhost:3000/assets/... 语句安静下来做(我在 Rails 3.2)。

在我的开发日志中,在 SQL 语句和缓存 片段 的 reads/writes 之后(仍然有用,我想保留),对于请求页面上使用的所有 js、css 和图像,有一长串缓存读取语句。只是为了展示一些:

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

我正在使用 quiet_assets gem as was suggested in another SO post,但这不适用于这些 "Cache read" 语句。

我在 config/environments/development.rb 中是否遗漏了一些不将这些输出到日志的简单设置?谢谢大家

编辑: 这是我的 development.rb 设置(我包含了任何可能相关的内容):

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

"Cache read" 行来自 Dalli 缓存后端,它们显示所有对 Dalli 缓存存储的访问。如果你只想为处理 "assets" 键的访问抑制这个调试行,但仍然有其他记录,你将不得不在 Rails 初始化程序中对 Dalli 进行猴子修补:

# 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

初始化器重新定义了Dalli store的log method,只有当key与"/assets/"字符串不匹配时才会真正记录缓存访问。如果是,则重新定义的 log 不执行任何操作。