开发者

How to set Rails Cache log level separately?

开发者 https://www.devze.com 2023-04-01 03:24 出处:网络
I use a pretty old rails version which is 2.3.2 because of legacy project. I set global log_level to :debug in our rails app. But since we also use开发者_如何学编程 Rails.cache the log file are full

I use a pretty old rails version which is 2.3.2 because of legacy project.

I set global log_level to :debug in our rails app. But since we also use开发者_如何学编程 Rails.cache the log file are full of annoying lines such as

Cache read: ...

Cache miss: ...

I want to just suppress these but not affect other 'more useful' info such as SQL logging.

How to do that?


Well, after initializing your cache store (in the example below, I use memory store) in your specific environment.rb file, you can redirect cache_store's log to a separate file and also tweak the logger level:

config.cache_store = ActiveSupport::Cache::MemoryStore.new(:expires_in => 5.minutes)
config.cache_store.logger = Logger.new("#{Rails.root}/log/#{ENV['RAILS_ENV']}_cache.log")
config.cache_store.logger.level = Logger::INFO

In addition to that, the cache store has a method called silence! that will turn off the logger :-|

config.cache_store.silence!
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号