Module: OnlineMigrations::VerboseSqlLogs

Defined in:
lib/online_migrations/verbose_sql_logs.rb

Class Method Summary collapse

Class Method Details

.disableObject



29
30
31
32
# File 'lib/online_migrations/verbose_sql_logs.rb', line 29

def disable
  ActiveRecord::Base.logger = @activerecord_logger_was
  set_verbose_query_logs(@verbose_query_logs_was)
end

.enableObject



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/online_migrations/verbose_sql_logs.rb', line 7

def enable
  @activerecord_logger_was = ActiveRecord::Base.logger
  @verbose_query_logs_was = verbose_query_logs
  return if @activerecord_logger_was.nil?

  stdout_logger = ActiveSupport::Logger.new($stdout)
  stdout_logger.formatter = @activerecord_logger_was.formatter
  stdout_logger.level = @activerecord_logger_was.level
  stdout_logger = ActiveSupport::TaggedLogging.new(stdout_logger)

  combined_logger =
    # Broadcasting logs API was changed in https://github.com/rails/rails/pull/48615.
    if Utils.ar_version >= 7.1
      ActiveSupport::BroadcastLogger.new(stdout_logger, @activerecord_logger_was)
    else
      stdout_logger.extend(ActiveSupport::Logger.broadcast(@activerecord_logger_was))
    end

  ActiveRecord::Base.logger = combined_logger
  set_verbose_query_logs(false)
end