Class: ROM::SQL::RailsLogSubscriber
- Inherits:
-
ActiveSupport::LogSubscriber
- Object
- ActiveSupport::LogSubscriber
- ROM::SQL::RailsLogSubscriber
- Defined in:
- lib/rom/sql/extensions/rails_log_subscriber.rb
Constant Summary collapse
- COLOR_OPTION =
if as_version && as_version >= Gem::Version.new("7.2") {color: true} else true end
Instance Method Summary collapse
Instance Method Details
#odd? ⇒ Boolean
44 45 46 |
# File 'lib/rom/sql/extensions/rails_log_subscriber.rb', line 44 def odd? @odd_or_even = !odd_or_even end |
#sql(event) ⇒ Object
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/rom/sql/extensions/rails_log_subscriber.rb', line 23 def sql(event) return unless logger.debug? payload = event.payload name = format('%s (%.1fms)', payload[:name], event.duration) sql = payload[:sql].squeeze(' ') binds = payload[:binds].to_a.inspect if payload[:binds] if odd? name = color(name, :cyan, COLOR_OPTION) sql = color(sql, nil, COLOR_OPTION) else name = color(name, :magenta, COLOR_OPTION) end debug " #{name} #{sql} #{binds}" end |