Class: Backup::Logger::Console
- Inherits:
-
Object
- Object
- Backup::Logger::Console
- 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
-
#initialize(_options = nil) ⇒ Console
constructor
A new instance of Console.
- #log(message) ⇒ Object
Constructor Details
#initialize(_options = nil) ⇒ Console
36 37 38 |
# File 'lib/backup/logger/console.rb', line 36 def initialize( = nil) $stdout.sync = $stderr.sync = true end |
Instance Method Details
#log(message) ⇒ Object
40 41 42 43 44 45 |
# File 'lib/backup/logger/console.rb', line 40 def log() io = .level == :info ? $stdout : $stderr lines = .formatted_lines lines.map! { |line| COLORS[.level] % line } if io.tty? io.puts lines end |