delayed_job not logging

后端 未结 4 1267
轻奢々
轻奢々 2020-12-18 02:07

I cannot log messages from my delayed_job process. Here is the job that is being run.

class MyJob
  def initialize(blahblah)
    @blahblah = blahblah
    @lo         


        
4条回答
  •  长情又很酷
    2020-12-18 02:36

    I don't see why you would set the logger in the job. When I've done this I set the worker to to use a specific file on start e.g. Logger.new("log/worker_#{worker_number}") which ensures that each worker outputs to it's own file and you don't have to worry about multiple workers writing to the same file at the same time (messy).

    Also, in plain ol' ruby you can call @logger.info "logging from delayed_job".

    Finally, i'm pretty sure that 'perform' is called directly by your worker and instantiated, so you can refactor to:

    class MyJob
     def perform(blahblah)
      @logger.add Logger::INFO, "logging from delayed_job"
      @blahblah = blahblah
      #do stuff
     end
    end
    

提交回复
热议问题