【问题标题】:rails: resque worker log doesn't honor log_tagsrails: resque worker 日志不尊重 log_tags
【发布时间】:2013-04-24 15:02:04
【问题描述】:

我的 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)>]

但是,日志条目仍然没有时间戳。 我对为什么会发生这种情况没有任何想法......

【问题讨论】:

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


    【解决方案1】:

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

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

    【讨论】:

      猜你喜欢
      • 2012-05-31
      • 1970-01-01
      • 1970-01-01
      • 2020-08-02
      • 2014-01-06
      • 2019-01-10
      • 2019-12-06
      • 2017-06-12
      • 1970-01-01
      相关资源
      最近更新 更多