jondot / sneakers

A fast background processing framework for Ruby and RabbitMQ
https://github.com/jondot/sneakers
MIT License
2.24k stars 333 forks source link

Logger is not initialised by default in a Rails 6 environment #395

Open molfar opened 5 years ago

molfar commented 5 years ago

I set up sneakers with rails project. Everything following instructions. But have this error:

Unexpected error undefined method `debug' for nil:NilClass
Did you mean?  debugger
  /Users/molfar/.rbenv/versions/2.5.3/lib/ruby/gems/2.5.0/gems/sneakers-2.11.0/lib/sneakers/worker.rb:114:in `worker_trace'
  /Users/molfar/.rbenv/versions/2.5.3/lib/ruby/gems/2.5.0/gems/sneakers-2.11.0/lib/sneakers/worker.rb:103:in `run'
  /Users/molfar/.rbenv/versions/2.5.3/lib/ruby/gems/2.5.0/gems/sneakers-2.11.0/lib/sneakers/workergroup.rb:42:in `block in run'
  /Users/molfar/.rbenv/versions/2.5.3/lib/ruby/gems/2.5.0/gems/sneakers-2.11.0/lib/sneakers/workergroup.rb:41:in `each'
  /Users/molfar/.rbenv/versions/2.5.3/lib/ruby/gems/2.5.0/gems/sneakers-2.11.0/lib/sneakers/workergroup.rb:41:in `run'

I think its because https://github.com/jondot/sneakers/blob/24abf5fb7069fd8c53bb28fd53f0fb55f2e4fd83/lib/sneakers/worker.rb#L123 does not check if logger exists. It will be better that sneakers use rails logger or stdout by default, with no config.

michaelklishin commented 5 years ago

This project is not tied to Rails. We should make the logging method more defensive. You are welcome to contribute a PR.

shime commented 4 years ago

I've managed to work around this problem (with Rails 6.0.0) by explicitly setting the logger.

Sneakers.logger = Rails.logger
Sneakers::Worker.logger = Rails.logger