我应该在 Rails 应用程序中的何处定义 resque 记录器

编程入门 行业动态 更新时间:2024-10-26 16:28:53
本文介绍了我应该在 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 记录器

本文发布于:2023-10-27 18:28:40,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1534183.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:记录器   应用程序   定义   Rails   resque

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!