diff --git a/lib/rom/sql/extensions/rails_log_subscriber.rb b/lib/rom/sql/extensions/rails_log_subscriber.rb index d4f76d93..7438f40d 100644 --- a/lib/rom/sql/extensions/rails_log_subscriber.rb +++ b/lib/rom/sql/extensions/rails_log_subscriber.rb @@ -15,10 +15,10 @@ def sql(event) binds = payload[:binds].to_a.inspect if payload[:binds] if odd? - name = color(name, :cyan, true) - sql = color(sql, nil, true) + name = color(name, :cyan, color_option) + sql = color(sql, nil, color_option) else - name = color(name, :magenta, true) + name = color(name, :magenta, color_option) end debug " #{name} #{sql} #{binds}" @@ -26,9 +26,20 @@ def sql(event) attr_reader :odd_or_even private :odd_or_even + def odd? @odd_or_even = !odd_or_even end + + private + + def color_option + if Gem::Version.new(Rails::VERSION::STRING) >= Gem::Version.new('7.1') + { color: true } + else + true + end + end end end end