rails:resque worker log不支持log_tags

时间:2013-04-24 15:02:04

标签: ruby-on-rails-3 logging resque

我的config / environments / development.rb中有以下行:

    config.log_tags = [lambda { |req| Time.now }]

完美适用于rails日志(它在每个条目前面加上时间戳)。

我想在我的resque工作者中有同样的行为。

的输出
p Rails.application.config.log_tags
在resque作业的perform方法中告诉我,其中有一个proc:

[#<Proc:0x007ffb36c14920@/.../config/environments/development.rb:49 (lambda)>]

但是,日志条目还没有时间戳。 对于为什么会发生这种情况,我的想法已经不多了......

1 个答案:

答案 0 :(得分:1)

在Rack中间件(Rails::Rack::Logger#call)中评估日志标记once per request。 Resque运行时没有Web请求,因此您什么也看不见。

要获得您想要的内容,您应该将类​​似于Rails::Rack::Logger#compute_tags的代码添加到Resque作为job hook,例如before_perform