我已经在 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 记录器
发布评论