Class: Dotsync::Logger
- Inherits:
-
Object
- Object
- Dotsync::Logger
- Defined in:
- lib/dotsync/utils/logger.rb
Instance Attribute Summary collapse
-
#output ⇒ Object
Returns the value of attribute output.
Instance Method Summary collapse
- #action(message, color: 153, bold: true, icon: :console) ⇒ Object
- #error(message, color: 196, bold: true, icon: :error) ⇒ Object
- #info(message, color: 103, bold: true, icon: :info) ⇒ Object
-
#initialize(output = $stdout) ⇒ Logger
constructor
NOTE: use Rake tasks “palette:fg” and “palette:bg” to select a proper ASCII color code.
- #log(message, color: 0, bold: false, icon: nil) ⇒ Object
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
#output ⇒ Object
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(, color: 153, bold: true, icon: :console) log(, 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(, color: 196, bold: true, icon: :error) log(, 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(, color: 103, bold: true, icon: :info) log(, 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(, 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 << msg << "\e[0m" if color > 0 # reset color msg = msg.join("") @output.puts msg end |