Class: Backup::Logger::Console

Inherits:
Object
  • Object
show all
Defined in:
lib/backup/logger/console.rb

Defined Under Namespace

Classes: Options

Constant Summary collapse

COLORS =
{
  :info   => "\e[32m%s\e[0m", # green
  :warn   => "\e[33m%s\e[0m", # yellow
  :error  => "\e[31m%s\e[0m"  # red
}

Instance Method Summary collapse

Constructor Details

#initialize(options = nil) ⇒ Console

Returns a new instance of Console.



38
39
40
# File 'lib/backup/logger/console.rb', line 38

def initialize(options = nil)
  $stdout.sync = $stderr.sync = true
end

Instance Method Details

#log(message) ⇒ Object



42
43
44
45
46
47
# File 'lib/backup/logger/console.rb', line 42

def log(message)
  io = message.level == :info ? $stdout : $stderr
  lines = message.formatted_lines
  lines.map! {|line| COLORS[message.level] % line } if io.tty?
  io.puts lines
end