7

I'm using Sidekiq to get some background jobs done. I am also trying to log some messages from these jobs to a log file, but I have been unable to do this simple task.

Example of the kind of job I'm running

class TestJob < ApplicationJob
  queue_as :default

  def perform
    text = 'Print me to a file!'
    Rails.logger.error "Rails.logger.info : #{text}"
    logger.error "logger.info : #{text}"
  end
end

Running TestJob.perform_now, in a controller action for example, works as expected, printing the messages to the server terminal output, as well as to logs/development.log.

But running TestJob.perform_later doesn't print my messages. Anywhere. Not to the Sidekiq terminal, the server terminal, log files, nothing.

I tried redirecting the logs, as suggested in the Sidekiq Logging wiki. But the messages didn't get printed there either.

I feel like I might be missing something crucial.

hananamar
  • 1,166
  • 15
  • 25
  • If Sidekiq is running and is picking up your job `log/sidekiq.log` will have `start` and `done` entries for `TestJob`. Are there any errors there? – cschroed Dec 04 '19 at 14:17
  • @cschroed nope... – hananamar Dec 07 '19 at 13:35
  • If the job is running then you could put this at the top of your `perform` method: `raise Rails.logger.inspect`. Then in the Sidekiq Dead Job queue you'll see more info about what the log level is and where it's sending its output. – cschroed Dec 08 '19 at 15:30

1 Answers1

3

Try to call Sidekiq.logger, as in:

    Sidekiq.logger.error "logger.info : #{text}"

Putting "logger.info" in the log of an error might be a little weird, but I was just taking from the example posted in the question.

cdmo
  • 1,239
  • 2
  • 14
  • 31