Tôi im lặng nhật ký CACHE sử dụng phương pháp được đề xuất bởi các bài liên kết dưới đây.
Tôi đã thay thế trình ghi nhật ký ActiveRecod mặc định bằng trình bao bọc lọc các thư có chứa văn bản không mong muốn, tức là 'CACHE'.
Đầu tiên, tạo một tập tin bên trong config/initializers
ví dụ active_record.rb
và bên trong các tập tin định nghĩa một lớp wrapper và thay thế các logger kỷ lục hoạt động như thế nào trong đoạn code dưới đây:
# Implementation of logger that ignores messages containing forbidden words
# here “CACHE” and "Settings Load"
class CacheFreeLogger < ActiveSupport::TaggedLogging
@@excluded = ['Settings Load','CACHE']
def add(severity, message = nil, progname = nil, &block)
if message.nil?
if block_given?
message = block.call
else
message = progname
progname = nil #No instance variable for this like Logger
end
end
if severity > Logger::DEBUG || !(@@excluded.map{|e| message.include? e}.include?(true))
@logger.add(severity, "#{tags_text}#{message}", progname)
end
end
end
#Replace the existing logger with the filtering one
ActiveRecord::Base.logger = CacheFreeLogger.new(ActiveRecord::Base.logger) if Rails.env.development?
Các bài gốc mở rộng Logger không TaggedLoggin nhưng nó không làm việc cho tôi.
Phương pháp này đã được đề xuất trong blog: http://heliom.ca/blog/posts/disable-rails-cache-logging
Tôi muốn biết làm thế nào để làm điều tương tự sử dụng đường ray 2.3.5 – Joelio