Class: MassiveRecord::ORM::LogSubscriber
- Inherits:
-
ActiveSupport::LogSubscriber
- Object
- ActiveSupport::LogSubscriber
- MassiveRecord::ORM::LogSubscriber
- Defined in:
- lib/massive_record/orm/log_subscriber.rb
Class Method Summary collapse
Instance Method Summary collapse
Class Method Details
.reset_runtime ⇒ Object
12 13 14 15 |
# File 'lib/massive_record/orm/log_subscriber.rb', line 12 def self.reset_runtime rt, self.runtime = runtime, 0 rt end |
.runtime ⇒ Object
8 9 10 |
# File 'lib/massive_record/orm/log_subscriber.rb', line 8 def self.runtime Thread.current["massive_record_query_runtime"] ||= 0 end |
.runtime=(value) ⇒ Object
4 5 6 |
# File 'lib/massive_record/orm/log_subscriber.rb', line 4 def self.runtime=(value) Thread.current["massive_record_query_runtime"] = value end |
Instance Method Details
#identity_map(event) ⇒ Object
45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/massive_record/orm/log_subscriber.rb', line 45 def identity_map(event) return unless logger.debug? payload = event.payload name = '%s (%.1fms)' % [payload[:name], event.duration] records = payload[:records] ids = "id(s): #{records.collect(&:id)}" if odd? name = color(name, CYAN, true) description = color(description, nil, true) else name = color(name, MAGENTA, true) end debug " " + [name, ids].compact.join(" ") end |
#load(event) ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/massive_record/orm/log_subscriber.rb', line 19 def load(event) self.class.runtime += event.duration return unless logger.debug? payload = event.payload name = '%s (%.1fms)' % [payload[:name], event.duration] description = payload[:description] = payload[:options] if .present? && .any? = "options: #{}" else = nil end if odd? name = color(name, CYAN, true) description = color(description, nil, true) else name = color(name, MAGENTA, true) end debug " " + [name, description, ].compact.join(" ") end |
#logger ⇒ Object
89 90 91 |
# File 'lib/massive_record/orm/log_subscriber.rb', line 89 def logger MassiveRecord::ORM::Base.logger end |
#query(event) ⇒ Object
63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 |
# File 'lib/massive_record/orm/log_subscriber.rb', line 63 def query(event) return unless logger.debug? payload = event.payload name = '%s (%.1fms)' % [payload[:name], event.duration] description = payload[:description] = payload[:options] if .present? && .any? = "options: #{}" else = nil end if odd? name = color(name, CYAN, true) description = color(description, nil, true) else name = color(name, MAGENTA, true) end debug " " + [name, description, ].compact.join(" ") end |