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
?
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With