5

本番環境でキャッシュのロギングを無効にしようとしています。SQL でクエリのログ記録を停止することに成功しましたが、ログ エントリのキャッシュには成功しませんでした。生産ログの行の例:

CACHE (0.0ms) SELECT `merchants`.* FROM `merchants` WHERE `merchants`.`id` = 1 LIMIT 1

logger.debug ステートメントを本番ログに表示したいので、すべてのロギングを無効にしたくありません。Rails 3.2.1 を Mysql と Apache で使用する。助言がありますか?

4

3 に答える 3

2

以下にリンクされている投稿で提案されている方法を使用して、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 ではなく Logger を拡張していましたが、うまくいきませんでした。

この方法はブログで提案されました: http://heliom.ca/blog/posts/disable-rails-cache-logging

于 2016-01-13T18:14:06.600 に答える