Module: RSMP::Logger::Colorization

Included in:
RSMP::Logger
Defined in:
lib/rsmp/log/colorization.rb

Overview

Handles colorization of log output

Instance Method Summary collapse

Instance Method Details

#apply_hash_colors(level, str) ⇒ Object



22
23
24
25
26
# File 'lib/rsmp/log/colorization.rb', line 22

def apply_hash_colors(level, str)
  colors = default_colors
  colors.merge! @settings['color'] if @settings['color'].is_a?(Hash)
  colorize_with_map(level, str, colors)
end

#colorize(level, str) ⇒ Object



28
29
30
31
32
33
34
35
36
37
38
# File 'lib/rsmp/log/colorization.rb', line 28

def colorize(level, str)
  return str if @settings['color'] == false || @settings['color'].nil?

  if @settings['color'] == true || @settings['color'].is_a?(Hash)
    apply_hash_colors(level, str)
  elsif i[nack warning error].include?(level)
    str.colorize(@settings['color']).bold
  else
    str.colorize @settings['color']
  end
end

#colorize_with_map(level, str, colors) ⇒ Object



17
18
19
20
# File 'lib/rsmp/log/colorization.rb', line 17

def colorize_with_map(level, str, colors)
  color = colors[level.to_s]
  color ? str.colorize(color.to_sym) : str
end

#default_colorsObject



5
6
7
8
9
10
11
12
13
14
15
# File 'lib/rsmp/log/colorization.rb', line 5

def default_colors
  {
    'info' => 'white',
    'log' => 'light_blue',
    'statistics' => 'light_black',
    'warning' => 'light_yellow',
    'error' => 'red',
    'debug' => 'light_black',
    'collect' => 'light_black'
  }
end