Class: ActiveRecord::LogSubscriber

Inherits:
ActiveSupport::EventReporter::LogSubscriber show all
Defined in:
activerecord/lib/active_record/log_subscriber.rb

Overview

:nodoc:

Constant Summary collapse

IGNORE_PAYLOAD_NAMES =
["SCHEMA", "EXPLAIN"]

Constants inherited from ActiveSupport::EventReporter::LogSubscriber

ActiveSupport::EventReporter::LogSubscriber::LEVEL_CHECKS

Constants included from ActiveSupport::ColorizeLogging

ActiveSupport::ColorizeLogging::BLACK, ActiveSupport::ColorizeLogging::BLUE, ActiveSupport::ColorizeLogging::CYAN, ActiveSupport::ColorizeLogging::GREEN, ActiveSupport::ColorizeLogging::MAGENTA, ActiveSupport::ColorizeLogging::MODES, ActiveSupport::ColorizeLogging::RED, ActiveSupport::ColorizeLogging::WHITE, ActiveSupport::ColorizeLogging::YELLOW

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from ActiveSupport::EventReporter::LogSubscriber

#emit, event_log_level, #logger, subscription_filter

Methods included from ActiveSupport::ColorizeLogging

#color, #colorize_logging, #error, #fatal, #info, #mode_from, #unknown, #warn

Methods included from ActiveSupport::Concern

#append_features, #class_methods, extended, #included, #prepend_features, #prepended

Class Method Details

.default_loggerObject



51
52
53
# File 'activerecord/lib/active_record/log_subscriber.rb', line 51

def self.default_logger
  ActiveRecord::Base.logger
end

Instance Method Details

#sql(event) ⇒ Object



25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'activerecord/lib/active_record/log_subscriber.rb', line 25

def sql(event)
  payload = event[:payload]

  return if IGNORE_PAYLOAD_NAMES.include?(payload[:name])

  name = if payload[:async]
    "ASYNC #{payload[:name]} (#{payload[:lock_wait].round(1)}ms) (db time #{payload[:duration_ms].round(1)}ms)"
  else
    "#{payload[:name]} (#{payload[:duration_ms].round(1)}ms)"
  end
  name  = "CACHE #{name}" if payload[:cached]
  sql   = payload[:sql]
  binds = payload[:binds]

  if payload[:binds]&.any?
    binds = binds.inspect
    binds.prepend("  ")
  end

  name = colorize_payload_name(name, payload[:name])
  sql  = color(sql, sql_color(sql), bold: true) if colorize_logging

  debug "  #{name}  #{sql}#{binds}"
end

#strict_loading_violation(event) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
22
# File 'activerecord/lib/active_record/log_subscriber.rb', line 11

def strict_loading_violation(event)
  debug do
    owner = event[:payload][:owner]
    klass = event[:payload][:class]
    name = event[:payload][:name]
    message = +"`#{owner}` is marked for strict_loading."
    message << " The #{klass ? "#{klass} association" : "polymorphic association"}"
    message << " named `:#{name}` cannot be lazily loaded."

    color(message, RED)
  end
end