Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Logging issues with Resque

I have added Resque to my Rails 3 project. I have created a job which reads/writes some stuff from/to the DB.

The problem is I do not see the SQL query logs such as "Post Load (0.5ms) SELECT "posts".* FROM "posts"" in the terminal anymore. I am also not seeing any Rails.logger messages I have set up.

When I make yet another request (simple refresh) the logger messages and SQL query logs suddenly show up.

Any ideas what could be going on? Thanks

like image 827
Martin Avatar asked Jun 28 '11 13:06

Martin


2 Answers

Rails won't write out to the log file immediately, it waits for a certain amount of lines to go by before flushing the file. You can tell Rails to always flush the log by adding this to your development.rb or application.rb file...

config.logger.auto_flushing = true

Only ever do this in development, and never set this in production as it will just kill your I/O.

You can also do it on demand with...

Rails.logger.flush

API documentation here...

http://api.rubyonrails.org/classes/ActiveSupport/BufferedLogger.html#method-i-auto_flushing-3D

like image 97
lloydpick Avatar answered Nov 16 '22 20:11

lloydpick


We experienced the same issue in one of our projects. Additionally we wanted to log all Resque messages to a separate log file too.

In the blog post Enable immediate log messages of resque workers a code sample can be found to enable the immediate logging to a separate file.

like image 2
anka Avatar answered Nov 16 '22 19:11

anka