Class: Yarder::ActiveRecord::LogSubscriber
- Inherits:
-
ActiveSupport::LogSubscriber
- Object
- ActiveSupport::LogSubscriber
- Yarder::ActiveRecord::LogSubscriber
- Defined in:
- lib/yarder/active_record/log_subscriber.rb
Class Method Summary collapse
Instance Method Summary collapse
- #identity(event) ⇒ Object
-
#initialize ⇒ LogSubscriber
constructor
A new instance of LogSubscriber.
- #sql(event) ⇒ Object
Constructor Details
#initialize ⇒ LogSubscriber
Returns a new instance of LogSubscriber.
20 21 22 |
# File 'lib/yarder/active_record/log_subscriber.rb', line 20 def initialize super end |
Class Method Details
.reset_runtime ⇒ Object
15 16 17 18 |
# File 'lib/yarder/active_record/log_subscriber.rb', line 15 def self.reset_runtime rt, self.runtime = runtime, 0 rt end |
.runtime ⇒ Object
11 12 13 |
# File 'lib/yarder/active_record/log_subscriber.rb', line 11 def self.runtime Thread.current["active_record_sql_runtime"] ||= 0 end |
.runtime=(value) ⇒ Object
7 8 9 |
# File 'lib/yarder/active_record/log_subscriber.rb', line 7 def self.runtime=(value) Thread.current["active_record_sql_runtime"] = value end |
Instance Method Details
#identity(event) ⇒ Object
50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/yarder/active_record/log_subscriber.rb', line 50 def identity(event) return unless logger.debug? payload = event.payload sql_entry = {} sql_entry['name'] = payload[:name] sql_entry['line'] = payload[:line] sql_entry['duration'] = payload[:duration] write_entry sql_entry end |
#sql(event) ⇒ Object
24 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 'lib/yarder/active_record/log_subscriber.rb', line 24 def sql(event) self.class.runtime += event.duration return unless logger.debug? payload = event.payload return if 'SCHEMA' == payload[:name] sql_entry = {} sql_entry['name'] = payload[:name] sql_entry['duration'] = event.duration sql_entry['sql']= payload[:sql].squeeze(' ') binds = nil unless (payload[:binds] || []).empty? binds = " " + payload[:binds].map { |col,v| [col.name, v] }.inspect end sql_entry['binds'] = binds unless binds.nil? write_entry sql_entry end |