How to ignore Delayed Job query logging in development on Rails

冷暖自知 提交于 2019-11-30 08:31:44

The log line still shows up because that line is logged by ActiveRecord, not Delayed Job. See the github bug report for more info on that. Here's a workaround:

in 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

I think you can set log level to one as follows in the initializers. It helps me to ignoring delayed job query info from the production as well as development log too.

ActiveRecord::Base.logger.level = 1

Change ActiveRecord log level only for Delayed job. This will allow you to see other ActiveRecord logs.

Use:

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