How to disable logging for rails 4 caching

2019-05-26 20:06发布

How can I disable logging for caching in "rails 4.1"? Specifically I'm trying to get rid of fragment caching log entries like these:

Write fragment views/... (0.3ms)
Read fragment views/... (0.3ms)

1条回答
Evening l夕情丶
2楼-- · 2019-05-26 20:30

How about this?

# config/initializers/log_subscriber.rb
module ActionController
  class LogSubscriber < ActiveSupport::LogSubscriber
    %w(write_fragment read_fragment exist_fragment?
       expire_fragment expire_page write_page).each do |method|
      class_eval <<-METHOD, __FILE__, __LINE__ + 1
        def #{method}(event)
          return
        end
      METHOD
    end
  end
end

Test locally with:

# config/environments/development.rb
config.action_controller.perform_caching = true

(With the usual caveat to test carefully in your own app. This "works," but is the hammer method, and can trap you or other, unwary programmers later.)

查看更多
登录 后发表回答