在一种特定情况下,我想为 sidekiq 后台作业使用替代日志文件。所以我实例化了一个新的 Logger,但问题是它不允许我使用调试:
include Sidekiq::Worker
def sidekiq_logger
@@sidekiq_logger ||= Logger.new("#{Rails.root}/log/sidekiq.log")
end
def perform(report_id)
report = Report.find(report_id)
distance = report.distance_formatted(report.unit)
sidekiq_logger.debug = "#{DateTime.now.to_s(:db)}: #{distance} processed for report #{report.id}"
report.update_attribute(:processed, true)
end
引发异常:
2013-07-16T13:17:35Z 10803 TID-tfkn8 ReportsWorker JID-e8f0f8a52277238c4851f231 INFO: fail: 0.007 sec
2013-07-16T13:17:35Z 10803 TID-tfkn8 WARN: {"retry"=>true, "queue"=>"default", "class"=>"ReportsWorker", "args"=>[317$
2013-07-16T13:17:35Z 10803 TID-tfkn8 WARN: undefined method `debug=' for #<Logger:0x00000006174d40>
那我该如何使用调试呢?