我試圖禁用生產中的緩存日誌記錄。已成功讓SQL停止記錄查詢,但沒有緩存日誌條目的運氣。例如線生產日誌:如何在rails中禁用activerecord緩存日誌記錄
CACHE (0.0ms) SELECT `merchants`.* FROM `merchants` WHERE `merchants`.`id` = 1 LIMIT 1
我不想禁用所有日誌,因爲我想logger.debug語句來生產日誌顯示出來。 在Mysql和Apache中使用rails 3.2.1。 有什麼建議嗎?
我試圖禁用生產中的緩存日誌記錄。已成功讓SQL停止記錄查詢,但沒有緩存日誌條目的運氣。例如線生產日誌:如何在rails中禁用activerecord緩存日誌記錄
CACHE (0.0ms) SELECT `merchants`.* FROM `merchants` WHERE `merchants`.`id` = 1 LIMIT 1
我不想禁用所有日誌,因爲我想logger.debug語句來生產日誌顯示出來。 在Mysql和Apache中使用rails 3.2.1。 有什麼建議嗎?
我使用下面鏈接後提出的方法沉默的CACHE日誌。
我用一個封裝器替換了默認的ActiveRecod記錄器,該封裝器可以過濾掉包含不需要的文本的消息,即'CACHE'。
首先,創建內部config/initializers
文件例如active_record.rb
和文件中定義一個包裝類並替換有效記錄日誌如下面的代碼:
# 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?
原帖擴展記錄儀不TaggedLoggin但沒有爲我工作。
此方法建議在博客:http://heliom.ca/blog/posts/disable-rails-cache-logging
這不適用於導軌5 – 2016-07-17 21:09:30
我想知道怎麼做使用Rails 2.3.5 – Joelio 2012-08-23 19:58:43