Logging issues with Resque

泪湿孤枕 提交于 2019-12-18 16:55:47

问题


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


回答1:


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




回答2:


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.




回答3:


Resque won't flush the log in production mode (unless your job is generating more than 1000 lines of log).

You will have to flush for every line of log generated. I would configure only resque with the file lib/tasks/resque.rake :

task "resque:setup" => :environment do
  Resque.before_first_fork = Proc.new { Rails.logger.auto_flushing = 1 }
end


来源:https://stackoverflow.com/questions/6507215/logging-issues-with-resque

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!