class RediSearch::LogSubscriber
Public Class Methods
reset_runtime()
click to toggle source
:nocov:
# File lib/redi_search/log_subscriber.rb, line 16 def self.reset_runtime rt, self.runtime = runtime, 0 rt end
runtime()
click to toggle source
# File lib/redi_search/log_subscriber.rb, line 11 def self.runtime Thread.current[:redi_search_runtime] ||= 0 end
runtime=(value)
click to toggle source
# File lib/redi_search/log_subscriber.rb, line 7 def self.runtime=(value) Thread.current[:redi_search_runtime] = value end
Public Instance Methods
action(event)
click to toggle source
:nocov:
# File lib/redi_search/log_subscriber.rb, line 22 def action(event) self.class.runtime += event.duration return unless logger.debug? command = command_string(event) debug_color = action_color(event.payload[:action]) debug " #{log_name(event)} #{color(command, debug_color, true)}" end
Private Instance Methods
action_color(action)
click to toggle source
rubocop:disable Metrics/MethodLength
# File lib/redi_search/log_subscriber.rb, line 39 def action_color(action) case action.to_sym when :search, :spellcheck then YELLOW when :create, :hset then GREEN when :dropindex, :del then RED when :hgetall, :info then CYAN when :pipeline then MAGENTA when :explaincli then BLUE end end
command_string(event)
click to toggle source
rubocop:enable Metrics/MethodLength
# File lib/redi_search/log_subscriber.rb, line 51 def command_string(event) event.payload[:query].flatten.map.with_index do |arg, i| arg = "FT.#{arg}" if prepend_ft?(arg, i) arg = arg.inspect if inspect_arg?(event.payload, arg) arg = " #{arg}" if event.payload[:inside_pipeline] arg end.join(" ") end
inspect_arg?(payload, arg)
click to toggle source
# File lib/redi_search/log_subscriber.rb, line 68 def inspect_arg?(payload, arg) multiword?(arg) && payload[:query].flatten.count > 1 end
log_name(event)
click to toggle source
# File lib/redi_search/log_subscriber.rb, line 34 def log_name(event) color("#{event.payload[:name]} (#{event.duration.round(1)}ms)", RED, true) end
multiword?(string)
click to toggle source
# File lib/redi_search/log_subscriber.rb, line 60 def multiword?(string) !string.to_s.start_with?(/\(-?@/) && string.to_s.split(/\s|\|/).size > 1 end
prepend_ft?(arg, index)
click to toggle source
# File lib/redi_search/log_subscriber.rb, line 64 def prepend_ft?(arg, index) index.zero? && !multiword?(arg) && %w(HSET HGETALL DEL).exclude?(arg.to_s) end