gpt4 book ai didi

ruby-on-rails-3.2 - 如何防止 Rails 从 Action View 登录生产

转载 作者:数据小太阳 更新时间:2023-10-29 08:11:02 24 4
gpt4 key购买 nike

在 rails 3.2.0 中,是否可以关闭用于呈现 View 的 rails 日志记录生产环境中的 ActionView::LogSubscriber。

目前我发现抑制的唯一方法是猴子修补它并增加日志级别以通过以下方式进行调试。是否有更好的方法或任何配置来执行此操作?

 module ActionView
class LogSubscriber
def render_template(event)
message = "Rendered #{from_rails_root(event.payload[:identifier])}"
message << " within #{from_rails_root(event.payload[:layout])}" if event.payload[:layout]
message << (" (%.1fms)" % event.duration)
debug(message)
end
alias :render_partial :render_template
alias :render_collection :render_template
end
end

最佳答案

ActionView 使用 ActiveSupport::Notifications ActiveSupport::LogSubscriber 检测其事件并从日志中将其静音非常简单,只需在您的环境文件中包含以下内容:

%w{render_template render_partial render_collection}.each do |event|
ActiveSupport::Notifications.unsubscribe "#{event}.action_view"
end

干杯!

关于ruby-on-rails-3.2 - 如何防止 Rails 从 Action View 登录生产,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50178577/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com