Skip to content

Commit

Permalink
Fix a LogSubscriber deprecation in Rails 7.1
Browse files Browse the repository at this point in the history
  • Loading branch information
jdelStrother committed Oct 11, 2023
1 parent 0c9768c commit cde7554
Showing 1 changed file with 16 additions and 4 deletions.
20 changes: 16 additions & 4 deletions lib/thinking_sphinx/active_record/log_subscriber.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,36 @@

class ThinkingSphinx::ActiveRecord::LogSubscriber < ActiveSupport::LogSubscriber
def guard(event)
identifier = color 'Sphinx', GREEN, true
identifier = colored_text "Sphinx"
warn " #{identifier} #{event.payload[:guard]}"
end

def message(event)
identifier = color 'Sphinx', GREEN, true
identifier = colored_text "Sphinx"
debug " #{identifier} #{event.payload[:message]}"
end

def query(event)
identifier = color('Sphinx Query (%.1fms)' % event.duration, GREEN, true)
identifier = colored_text("Sphinx Query (%.1fms)" % event.duration)
debug " #{identifier} #{event.payload[:query]}"
end

def caution(event)
identifier = color 'Sphinx', GREEN, true
identifier = colored_text "Sphinx"
warn " #{identifier} #{event.payload[:caution]}"
end

private

if Rails.gem_version >= Gem::Version.new("7.1.0")
def colored_text(text)
color text, GREEN, bold: true
end
else
def colored_text(text)
color text, GREEN, true
end
end
end

ThinkingSphinx::ActiveRecord::LogSubscriber.attach_to :thinking_sphinx

0 comments on commit cde7554

Please sign in to comment.