SQL specification for rails registration

In my rails application, I have a background process runner, the name of the model is Worker, which checks for new tasks to start every 10 seconds. This check generates two SQL queries each time - one to search for new jobs, one to delete old completed ones.

The problem with this is that the main log file receives spam for each of these requests.

Can I route the SQL queries generated by the Worker model to a separate log file, or at least silence them? Overwriting Worker.logger does not work - it only redirects messages that explicitly call logger.debug ("something").

+3
source share
3 answers

The simplest and most idiomatic solution

logger.silence do
  do_something
end

See Logger of Silence

+4
source

Requests are logged at the adapter level, as I showed here. How to get the latest SQL query executed by ActiveRecord in Ruby on Rails?

You cannot change the behavior unless you configure the behavior of the adapter to some really terrible hacks.

0
source
class Worker < ActiveRecord::Base
  def run
    old_level, self.class.logger.level = self.class.logger.level, Logger::WARN

    run_outstanding_jobs
    remove_obsolete_jobs
  ensure
    self.class.logger.level = old_level
  end
end

. , . , , ActiveRecord:: Base.logger , .

: ActiveRecord, ActionController, ActionView, ActionMailer ActiveResource. , Logger.

0
source

Source: https://habr.com/ru/post/1713441/


All Articles