jeudi 2 juillet 2015

How to disable logs for fragment caching in rails

Hello I have a application in which continuously the log is being written by:

Read fragment views/locations/946-20150420170206 (0.1ms)
Read fragment views/locations/947-20150420170206 (0.1ms)
Read fragment views/locations/948-20150420170206 (0.1ms)
Read fragment views/locations/949-20150420170206 (0.1ms)
Read fragment views/locations/950-20150420170206 (0.1ms)
Read fragment views/locations/951-20150420170206 (0.1ms)
Read fragment views/locations/952-20150420170206 (0.1ms)
Read fragment views/locations/953-20150420170206 (0.1ms)
Read fragment views/locations/954-20150420170206 (0.1ms)
Read fragment views/locations/955-20150420170206 (0.1ms)
Read fragment views/locations/956-20150420170206 (0.1ms)
Read fragment views/locations/957-20150420170206 (0.1ms)
Read fragment views/locations/958-20150420170206 (0.1ms)
Read fragment views/locations/959-20150420170206 (0.1ms)
Read fragment views/locations/960-20150420170206 (0.1ms)
Read fragment views/locations/961-20150420170206 (0.1ms)
Read fragment views/locations/962-20150420170206 (0.1ms)
Read fragment views/locations/963-20150420170207 (0.1ms)
Read fragment views/locations/964-20150420170207 (0.1ms)
Read fragment views/locations/965-20150420170207 (0.1ms)
Read fragment views/locations/966-20150420170207 (0.1ms)
Read fragment views/locations/967-20150420170207 (0.1ms)
Read fragment views/locations/968-20150420170207 (0.1ms)
Read fragment views/locations/969-20150420170207 (0.1ms)
Read fragment views/locations/970-20150420170207 (0.1ms)
Read fragment views/locations/971-20150420170207 (0.1ms)
Read fragment views/locations/972-20150420170207 (0.1ms)

which is filling the log and making the file in some GB size. So I want to disable the logs for the cache read and write so I can stop this. I have tried various things:

module ActionView
  class LogSubscriber < ActiveSupport::LogSubscriber
    def logger
      @memoized_logger ||= Logger.new('/dev/null')
    end
  end
end

I kept this file in initializers folder but didn't help. The second thing in initializer I tried is:

Rails.cache.silence!

But still nothing changed. Also I tried this in production.rb:

config.cache_store.silence!

But this threw an error. I think probably there is no cache_store defined.

Also in the initializers I tried this:

# Create logger that ignores messages containing “CACHE”
class CacheFreeLogger < ::Logger
  def debug(message, *args, &block)
    super unless message.include? 'CACHE'
  end
end

# Overwrite ActiveRecord’s logger
ActiveRecord::Base.logger = ActiveSupport::TaggedLogging.new(
  CacheFreeLogger.new(STDOUT)) unless Rails.env.test?

Still no help.

I got another answer which might help but I don't know how to use this. Here is the link:

How to disable logging for rails 4 caching

Can someone please help me disabling the logs for this. Thanks in advance.

Aucun commentaire:

Enregistrer un commentaire