Reputation: 1284
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.
Upvotes: 8
Views: 3275
Reputation: 1319
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.
Upvotes: 3