Class: RailsSemanticLogger::ActiveRecord::LogSubscriber
- Inherits:
-
ActiveSupport::LogSubscriber
- Object
- ActiveSupport::LogSubscriber
- RailsSemanticLogger::ActiveRecord::LogSubscriber
- Defined in:
- lib/rails_semantic_logger/active_record/log_subscriber.rb
Constant Summary collapse
- IGNORE_PAYLOAD_NAMES =
%w[SCHEMA EXPLAIN].freeze
Class Attribute Summary collapse
-
.logger ⇒ Object
readonly
Returns the value of attribute logger.
Class Method Summary collapse
Instance Method Summary collapse
Class Attribute Details
.logger ⇒ Object (readonly)
Returns the value of attribute logger.
7 8 9 |
# File 'lib/rails_semantic_logger/active_record/log_subscriber.rb', line 7 def logger @logger end |
Class Method Details
.reset_runtime ⇒ Object
18 19 20 21 22 |
# File 'lib/rails_semantic_logger/active_record/log_subscriber.rb', line 18 def self.reset_runtime rt = runtime self.runtime = 0 rt end |
.runtime ⇒ Object
14 15 16 |
# File 'lib/rails_semantic_logger/active_record/log_subscriber.rb', line 14 def self.runtime ::ActiveRecord::RuntimeRegistry.sql_runtime ||= 0 end |
.runtime=(value) ⇒ Object
10 11 12 |
# File 'lib/rails_semantic_logger/active_record/log_subscriber.rb', line 10 def self.runtime=(value) ::ActiveRecord::RuntimeRegistry.sql_runtime = value end |
Instance Method Details
#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 |
# File 'lib/rails_semantic_logger/active_record/log_subscriber.rb', line 24 def sql(event) self.class.runtime += event.duration return unless logger.debug? payload = event.payload name = payload[:name] return if IGNORE_PAYLOAD_NAMES.include?(name) log_payload = {sql: payload[:sql]} log_payload[:binds] = bind_values(payload) unless (payload[:binds] || []).empty? 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 end logger.debug(log) end |