Module: DbDebug::Logger

Defined in:
lib/db_debug/logger.rb

Constant Summary collapse

COLOR_MAP =
{
  :black => 30,
  :red  => 31,
  :green  => 32,
  :yellow  => 33,
  :blue  => 34,
  :magenta  => 35,
  :cyan  => 36,
  :white => 37
}

Class Method Summary collapse

Class Method Details

.determine_color(count, time) ⇒ Object



24
25
26
27
28
29
30
31
32
# File 'lib/db_debug/logger.rb', line 24

def self.determine_color count, time
  if count <= 10 || time < 50.0
    :green
  elsif count <= 20 || time < 100.0
    :yellow
  else
    :red
  end
end

.log(color, str) ⇒ Object



14
15
16
17
18
19
20
21
22
# File 'lib/db_debug/logger.rb', line 14

def self.log color, str
  code = COLOR_MAP[color]
  str = "\033[0;#{code}m#{str}\033[0;#37m"  
  if self.private_methods.include? 'irb_binding'
    puts str
  else
    Rails.logger.debug str
  end
end