class GroongaClientModel::LogSubscriber

Public Class Methods

measure() { || ... } click to toggle source
# File lib/groonga_client_model/log_subscriber.rb, line 39
def measure
  before_runtime = runtime
  yield
  runtime - before_runtime
end
reset_runtime() click to toggle source
# File lib/groonga_client_model/log_subscriber.rb, line 35
def reset_runtime
  self.runtime = 0.0
end
runtime() click to toggle source
# File lib/groonga_client_model/log_subscriber.rb, line 24
def runtime
  Thread.current["groonga_client_model.log_subscriber.runtime"]
end
runtime=(value) click to toggle source
# File lib/groonga_client_model/log_subscriber.rb, line 28
def runtime=(value)
  Thread.current["groonga_client_model.log_subscriber.runtime"] = value
end

Public Instance Methods

groonga(event) click to toggle source
# File lib/groonga_client_model/log_subscriber.rb, line 46
def groonga(event)
  self.class.runtime = (self.class.runtime || 0) + event.duration

  debug do
    command = event.payload[:command]

    title = color("#{command.command_name} (#{event.duration.round(1)}ms)",
                  title_color(command),
                  true)
    formatted_command = color(command.to_command_format,
                              command_color(command),
                              true)
    "  #{title}  #{formatted_command}"
  end
end

Private Instance Methods

command_color(command) click to toggle source
# File lib/groonga_client_model/log_subscriber.rb, line 71
def command_color(command)
  case command.command_name
  when "select"
    BLUE
  when "load"
    GREEN
  when "delete"
    RED
  else
    MAGENTA
  end
end
logger() click to toggle source
# File lib/groonga_client_model/log_subscriber.rb, line 84
def logger
  GroongaClientModel.logger
end
title_color(command) click to toggle source
# File lib/groonga_client_model/log_subscriber.rb, line 63
def title_color(command)
  if command.command_name == "select"
    MAGENTA
  else
    CYAN
  end
end