gpt4 book ai didi

ruby-on-rails - 如何在 Rails 开发中忽略延迟作业查询日志记录

转载 作者:行者123 更新时间:2023-12-03 21:30:11 28 4
gpt4 key购买 nike

我将如何静音/忽略来自 log/development.log 的这些延迟作业查询日志?

Delayed::Backend::ActiveRecord::Job Load (1.0ms)  UPDATE "delayed_jobs" SET locked_at = '2013-11-19 19:55:45.053991', locked_by = 'host:desktop-virtual pid:22277' WHERE id IN (SELECT id FROM "delayed_jobs" WHERE ((run_at <= '2013-11-19 19:55:45.053435' AND (locked_at IS NULL OR locked_at < '2013-11-19 15:55:45.053519') OR locked_by = 'host:desktop-virtual pid:22277') AND failed_at IS NULL) ORDER BY priority ASC, run_at ASC LIMIT 1 FOR UPDATE) RETURNING *
Delayed::Backend::ActiveRecord::Job Load (1.4ms) UPDATE "delayed_jobs" SET locked_at = '2013-11-19 19:55:50.056977', locked_by = 'host:desktop-virtual pid:22277' WHERE id IN (SELECT id FROM "delayed_jobs" WHERE ((run_at <= '2013-11-19 19:55:50.056484' AND (locked_at IS NULL OR locked_at < '2013-11-19 15:55:50.056530') OR locked_by = 'host:desktop-virtual pid:22277') AND failed_at IS NULL) ORDER BY priority ASC, run_at ASC LIMIT 1 FOR UPDATE) RETURNING *

我试过将此添加到 config/initializers/delayed_job.rb它路由除了间隔查询日志之外的所有内容,这些日志仍然放在 log/development.log 中.
if Rails.env == "development"
Delayed::Worker.logger = Logger.new(File.join(Rails.root, "log", "delayed_job.log"))
end

谢谢你。

最佳答案

日志行仍然显示,因为该行是由 ActiveRecord 记录的,而不是 Delayed Job。见 github bug report有关更多信息。这是一个解决方法:

config/initializers/delayed_job_silencer.rb :

if Rails.env.development?
module Delayed
module Backend
module ActiveRecord
class Job
class << self
alias_method :reserve_original, :reserve
def reserve(worker, max_run_time = Worker.max_run_time)
previous_level = ::ActiveRecord::Base.logger.level
::ActiveRecord::Base.logger.level = Logger::WARN if previous_level < Logger::WARN
value = reserve_original(worker, max_run_time)
::ActiveRecord::Base.logger.level = previous_level
value
end
end
end
end
end
end
end

关于ruby-on-rails - 如何在 Rails 开发中忽略延迟作业查询日志记录,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20081186/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com