如何禁用 rails 4 缓存的日志记录 [英] How to disable logging for rails 4 caching
本文介绍了如何禁用 rails 4 缓存的日志记录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何禁用rails 4.1"中的缓存日志记录?具体来说,我试图摆脱这样的片段缓存日志条目:
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)
推荐答案
这个怎么样?
# 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
本地测试:
# 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.)
这篇关于如何禁用 rails 4 缓存的日志记录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文