Class: Dotsync::Logger

Inherits:
Object
  • Object
show all
Defined in:
lib/dotsync/utils/logger.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(output = $stdout) ⇒ Logger

NOTE: use Rake tasks “palette:fg” and “palette:bg” to select a proper ASCII color code



9
10
11
# File 'lib/dotsync/utils/logger.rb', line 9

def initialize(output = $stdout)
  @output = output
end

Instance Attribute Details

#outputObject

Returns the value of attribute output.



5
6
7
# File 'lib/dotsync/utils/logger.rb', line 5

def output
  @output
end

Instance Method Details

#action(message, color: 153, bold: true, icon: :console) ⇒ Object



13
14
15
# File 'lib/dotsync/utils/logger.rb', line 13

def action(message, color: 153, bold: true, icon: :console)
  log(message, color: color, bold: bold, icon: icon)
end

#error(message, color: 196, bold: true, icon: :error) ⇒ Object



21
22
23
# File 'lib/dotsync/utils/logger.rb', line 21

def error(message, color: 196, bold: true, icon: :error)
  log(message, color: color, bold: bold, icon: icon)
end

#info(message, color: 103, bold: true, icon: :info) ⇒ Object



17
18
19
# File 'lib/dotsync/utils/logger.rb', line 17

def info(message, color: 103, bold: true, icon: :info)
  log(message, color: color, bold: bold, icon: icon)
end

#log(message, color: 0, bold: false, icon: nil) ⇒ Object



25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/dotsync/utils/logger.rb', line 25

def log(message, color: 0, bold: false, icon: nil)
  mapped_icon = Dotsync::Icons::MAPPINGS[icon] if icon

  msg = []
  msg << "\e[38;5;#{color}m" if color > 0
  msg << "\e[1m" if bold
  msg << mapped_icon if mapped_icon
  msg << message
  msg << "\e[0m" if color > 0 # reset color
  msg = msg.join("")

  @output.puts msg
end