Delayed Job not logging in Production

▼魔方 西西 提交于 2019-12-31 22:36:32

问题


I want my delayed job "code" to log in a different log file for business requirements. So I log a custom status in a log called as dj.log. Inside the "serialized" job, I am putting the log statements to log in my file.

Here is how the setup is

Delayed::Worker.destroy_failed_jobs = false
Delayed::Worker.sleep_delay = 60
Delayed::Worker.max_attempts = 10
Delayed::Worker.delay_jobs = !( Rails.env.test? || Rails.env.development? ) #dont use delayed_job in development or test mode

#Delayed_job custom logger
DJ_LOGFILE = File.join(Rails.root, 'log', 'dj.log')

and here is the job that the workers actually do

    people.each {|p| Mailer.mail(1233, p).deliver; sent_to << p.email }                
    Logger.new(DJ_LOGFILE).info("[DELIVERED] All Emails delivered (#{sent_to.join(", ")})")

what could be the problem here ? please help


回答1:


DelayedJob maintains it's own logger so you'll need to point that to your specific log file. So, in your initializer file (either environment.rb or, better, a specific delayed_job.rb file in config/initializers) add the following:

Delayed::Worker.logger = Logger.new(File.join(Rails.root, 'log', 'dj.log'))



回答2:


The problem is this bug: https://github.com/collectiveidea/delayed_job/issues/382 . . . . .




回答3:


Here is my solution (tested with 2.1.4):

config/initializers/delayed_job.rb

Delayed::Worker.logger ||= Logger.new(File.join(Rails.root, 'log', 'delayed_job.log'))


来源:https://stackoverflow.com/questions/6183676/delayed-job-not-logging-in-production

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!