简体   繁体   English

我应该在rails应用程序中定义resque logger的位置

[英]Where should I define my resque logger in my rails application

I have set up Resque in my rails application and it's all working fine. 我在我的rails应用程序中设置了Resque,它一切正常。 The question I have is where should the logger setup go. 我的问题是记录器设置应该放在哪里。 Should it be in the initializer or in the rake task? 它应该在初始化程序中还是在rake任务中? It works when set up in both. 它在两者中设置时都有效。 The reason I ask is I have seen it used in both in examples across the net. 我问的原因是我已经看到它在网上的例子中都使用过。

I am thinking that it should probably be in the initializer as it's best practice to put setup into initializers. 我认为它应该在初始化器中,因为将setup设置为初始化器是最佳实践。

config/initializers/resque.rb 配置/初始化/ resque.rb

logfile = File.open(File.join(Rails.root, 'log', 'resque.log'), 'a')
logfile.sync = true
Resque.logger = ActiveSupport::Logger.new(logfile)
Resque.logger.level = Logger::INFO

I am then writing out using the Resque.logger syntax in the rake task and jobs. 然后我在rake任务和作业中使用Resque.logger语法写出来。

EG: 例如:

Resque.logger.info "Resque task started!"

Many thanks in advance. 提前谢谢了。

EDIT 编辑
I'll stick with the initializer then. 我会坚持使用初始化程序。

我肯定会把它放在初始化器中,因为它只需要调用一次,同时设置你的服务器。

Another choice: config the resque logger inside every job if config it in initializer( config/initializers/resquer.rb ) or rake ( lib/tasks/resque.rake ) neither work for you, it is not perfect but just works. 另一个选择:如果在初始化程序( config/initializers/resquer.rb )或rake( lib/tasks/resque.rake )中配置它,那么在每个作业中配置resque记录器都不适用于你,它不完美但只是起作用。

class OneJob
  def self.perform
    Resque.logger = Logger.new("#{Rails.root}/log/resque.log")
    Resque.logger.level = Logger::DEBUG   

    Resque.logger.info 'Job starts'
    ...
  end
en

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM