Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Where should I define my resque logger in my rails application

I have set up Resque in my rails application and it's all working fine. The question I have is where should the logger setup go. Should it be in the initializer or in the rake task? It works when set up in both. The reason I ask is I have seen it used in both in examples across the net.

I am thinking that it should probably be in the initializer as it's best practice to put setup into initializers.

config/initializers/resque.rb

logfile = File.open(File.join(Rails.root, 'log', 'resque.log'), 'a')
logfile.sync = true
Resque.logger = ActiveSupport::Logger.new(logfile)
Resque.logger.level = Logger::INFO

I am then writing out using the Resque.logger syntax in the rake task and jobs.

E.G:

Resque.logger.info "Resque task started!"

Many thanks in advance.

EDIT
I'll stick with the initializer then.

like image 834
Mark Davies Avatar asked Sep 27 '22 15:09

Mark Davies


1 Answers

I would definitely put it inside initializer, since it needs to be called only once, while setting up your server.

like image 121
Piotr Kruczek Avatar answered Oct 13 '22 01:10

Piotr Kruczek