Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Prevent Sidekiq from printing "(...) INFO: Sidekiq client with redis options {}" on tests

I use Rails 4 default testing framework and have written some tests that also expect Sidekiq to do some work in the "background". But when I run rake test my test results look something like this:

.............2014-08-01T05:40:52Z 12000 TID-abcdef123 INFO: Sidekiq client with redis options {}
.....................................

Finished in 3.0s, 9.000 runs/s, 150.000 assertions/s.
30 runs, 400 assertions, 0 failures, 0 errors, 0 skips

Now this looks fine with the tests but the log of the Sidekiq worker is really annoying. To prevent this log from happening I have tried this in my worker class:

class MyWorker
  include Sidekiq::Worker
  sidekiq_options queue: :my_queue

  def initialize
    Rails.logger.level = 2 # set to :warn level
    super
  end

  def perform(movie_id)
    # Rails.logger.level = 0 # set back to :debug level?

    # some code
  end
end

With both the Rails.logger.level line commented and uncommented, but the logged line didn't disappear. How can I prevent Sidekiq from logging this when run with rake test?

like image 394
Jeehut Avatar asked Sep 06 '25 03:09

Jeehut


1 Answers

You can add the following line to your sidekiq initializer (config/initializers/sidekiq.rb) to turn it off:

if Rails.env.test?
  Sidekiq.logger.level = Logger::WARN
end
like image 168
infused Avatar answered Sep 07 '25 19:09

infused