Ruby-on-rails 登录 delay_job?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/14631910/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Logging in delayed_job?
提问by Stefan Kendall
I can't get any log output from delayed_job, and I'm not sure my jobs are starting.
我无法从 获得任何日志输出delayed_job,而且我不确定我的工作是否正在开始。
Here's my Procfile:
这是我的 Procfile:
web: bundle exec rails server
worker: bundle exec rake jobs:work
worker: bundle exec clockwork app/clock.rb
And here's the job:
这是工作:
class ScanningJob
def perform
logger.info "logging from delayed_job"
end
def after(job)
Rails.logger.info "logging from after delayed_job"
end
end
I see that clockwork outputs to system out, and I can see worker executor starting, but I never see my log statements hit. I tried putsas well to no avail.
我看到发条输出到系统输出,我可以看到工作执行程序正在启动,但我从未看到我的日志语句被命中。我也试过puts了,没用。
My clock file is pretty simple:
我的时钟文件非常简单:
every(3.seconds, 'refreshlistings') { Delayed::Job.enqueue ScanningJob.new }
I just want to see this working, and lack of logging means I can't. What's going on here?
我只想看到这个工作,缺乏日志记录意味着我不能。这里发生了什么?
回答by James Chevalier
When I needed log output from Delayed Jobs, I found this questionto be fairly helpful.
当我需要 Delayed Jobs 的日志输出时,我发现这个问题很有帮助。
In config/initializers/delayed_job.rbI add the line:
在config/initializers/delayed_job.rb我添加行:
Delayed::Worker.logger = Logger.new(File.join(Rails.root, 'log', 'dj.log'))
Then, in my job, I output to this log with:
然后,在我的工作中,我输出到这个日志:
Delayed::Worker.logger.info("Log Entry")
This results in the file log/dj.logbeing written to. This works in development, staging, and production environments.
这导致文件log/dj.log被写入。这适用于开发、登台和生产环境。

