Class: RailsSemanticLogger::Sequel::LogSubscriber
- Inherits:
-
ActiveSupport::LogSubscriber
- Object
- ActiveSupport::LogSubscriber
- RailsSemanticLogger::Sequel::LogSubscriber
- Defined in:
- lib/rails_semantic_logger/sequel/log_subscriber.rb
Class Attribute Summary collapse
-
.logger ⇒ Object
readonly
Returns the value of attribute logger.
Class Method Summary collapse
- .count ⇒ Object
- .count=(value) ⇒ Object
- .reset_count ⇒ Object
- .reset_runtime ⇒ Object
- .runtime ⇒ Object
- .runtime=(value) ⇒ Object
Instance Method Summary collapse
Class Attribute Details
.logger ⇒ Object (readonly)
Returns the value of attribute logger.
7 8 9 |
# File 'lib/rails_semantic_logger/sequel/log_subscriber.rb', line 7 def logger @logger end |
Class Method Details
.count ⇒ Object
24 25 26 |
# File 'lib/rails_semantic_logger/sequel/log_subscriber.rb', line 24 def self.count RequestStore.fetch(:sql_count) { 0 } end |
.count=(value) ⇒ Object
20 21 22 |
# File 'lib/rails_semantic_logger/sequel/log_subscriber.rb', line 20 def self.count= value RequestStore.store[:sql_count] = value end |
.reset_count ⇒ Object
34 35 36 37 38 |
# File 'lib/rails_semantic_logger/sequel/log_subscriber.rb', line 34 def self.reset_count previous = count self.count = 0 previous end |
.reset_runtime ⇒ Object
28 29 30 31 32 |
# File 'lib/rails_semantic_logger/sequel/log_subscriber.rb', line 28 def self.reset_runtime previous = runtime self.runtime = 0 previous end |
.runtime ⇒ Object
15 16 17 18 |
# File 'lib/rails_semantic_logger/sequel/log_subscriber.rb', line 15 def self.runtime # ::ActiveRecord::RuntimeRegistry.sql_runtime ||= 0 RequestStore.fetch(:sql_runtime) { 0 } end |
.runtime=(value) ⇒ Object
10 11 12 13 |
# File 'lib/rails_semantic_logger/sequel/log_subscriber.rb', line 10 def self.runtime= value # ::ActiveRecord::RuntimeRegistry.sql_runtime = value RequestStore.store[:sql_runtime] = value end |
Instance Method Details
#sql(event) ⇒ Object
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/rails_semantic_logger/sequel/log_subscriber.rb', line 40 def sql event self.class.runtime += event.duration self.class.count += 1 return unless logger.debug? payload = event.payload name = payload[:name] log_payload = {sql: payload[:sql].squeeze(" ")} log_payload[:binds] = bind_values payload unless (payload[:binds] || []).empty? log_payload[:allocations] = event.allocations if event.respond_to? :allocations log_payload[:cached] = event.payload[:cached] log = {message: name, payload: log_payload, duration: event.duration} # Log the location of the query itself. if logger.send(:level_index) >= SemanticLogger.backtrace_level_index log[:backtrace] = SemanticLogger::Utils.strip_backtrace caller end logger.debug log end |