How to disable activerecord caching logging on rails

I am trying to disable production caching logging. Managed to force SQL to stop query logging, but no luck with caching log entries. Example line in the production log:

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

I do not want to disable all logging, as I want the logger.debug statements to appear in the production log. Using rails 3.2.1 with Mysql and Apache. Any suggestions?

+5
source share
2 answers

I disabled the CACHE log using the method suggested by the post related below.

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?

Logger, TaggedLoggin, .

: http://heliom.ca/blog/posts/disable-rails-cache-logging

+2

(this, this, ), SO . :

old_logger = ActiveRecord::Base.logger
ActiveRecord::Base.logger = nil

:

ActiveRecord::Base.logger = old_logger; nil # nil just to suppress some garbage 
-1

All Articles