我应该在 Rails 应用程序中的何处定义 resque 记录器 [英] Where should I define my resque logger in my rails application

查看:37
本文介绍了我应该在 Rails 应用程序中的何处定义 resque 记录器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经在 Rails 应用程序中设置了 Resque,一切正常.我的问题是记录器设置应该去哪里.它应该在初始化程序中还是在 rake 任务中?在两者中设置时它都有效.我问的原因是我在网上的两个例子中都看到了它.

I have set up Resque in my rails application and it's all working fine. The question I have is where should the logger setup go. Should it be in the initializer or in the rake task? 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.

config/initializers/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

然后我在 rake 任务和作业中使用 Resque.logger 语法写出.

I am then writing out using the Resque.logger syntax in the rake task and jobs.

例如:

Resque.logger.info "Resque task started!"

非常感谢.

编辑
那么我会坚持使用初始值设定项.

EDIT
I'll stick with the initializer then.

推荐答案

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

I would definitely put it inside initializer, since it needs to be called only once, while setting up your server.

这篇关于我应该在 Rails 应用程序中的何处定义 resque 记录器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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