如何分别设置Rails Cache日志级别? [英] How to set Rails Cache log level separately?

查看:88
本文介绍了如何分别设置Rails Cache日志级别?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

由于遗留项目,我使用的是很旧的Rails版本2.3.2.

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

我在rails应用程序中将global log_level设置为:debug.但是,由于我们也使用Rails.cache,因此日志文件中充满了烦人的行,例如
缓存读取:...
缓存未命中:...

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: ...

我只想抑制这些,但不影响其他更有用的"信息,例如SQL日志记录.

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

该怎么做?

推荐答案

好了,在您的特定environment.rb文件中初始化缓存存储(在下面的示例中,我使用内存存储)之后,您可以将cache_store的日志重定向到单独的文件,并调整记录器级别:

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/#{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!

这篇关于如何分别设置Rails Cache日志级别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆