Class: ChefBackup::Logger
- Inherits:
-
Object
- Object
- ChefBackup::Logger
- Defined in:
- lib/chef_backup/logger.rb
Overview
Basic Logging Class
Instance Attribute Summary collapse
-
#stdout ⇒ Object
Returns the value of attribute stdout.
Class Method Summary collapse
Instance Method Summary collapse
- #color? ⇒ Boolean
-
#initialize(logfile = nil) ⇒ Logger
constructor
A new instance of Logger.
- #log(msg, level = :info) ⇒ Object
Constructor Details
#initialize(logfile = nil) ⇒ Logger
Returns a new instance of Logger.
17 18 19 20 |
# File 'lib/chef_backup/logger.rb', line 17 def initialize(logfile = nil) $stdout = logfile ? File.open(logfile, "ab") : $stdout @highline = HighLine.new($stdin, $stdout) end |
Instance Attribute Details
#stdout ⇒ Object
Returns the value of attribute stdout.
15 16 17 |
# File 'lib/chef_backup/logger.rb', line 15 def stdout @stdout end |
Class Method Details
.log(msg, level = :info) ⇒ Object
11 12 13 |
# File 'lib/chef_backup/logger.rb', line 11 def self.log(msg, level = :info) logger.log(msg, level) end |
.logger(logfile = nil) ⇒ Object
6 7 8 9 |
# File 'lib/chef_backup/logger.rb', line 6 def self.logger(logfile = nil) @logger = nil if @logger && logfile && @logger.stdout != logfile @logger ||= new(logfile) end |
Instance Method Details
#color? ⇒ Boolean
35 36 37 |
# File 'lib/chef_backup/logger.rb', line 35 def color? $stdout.tty? end |
#log(msg, level = :info) ⇒ Object
22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/chef_backup/logger.rb', line 22 def log(msg, level = :info) case level when :warn msg = "WARNING: #{msg}" $stdout.puts(color? ? @highline.color(msg, :yellow) : msg) when :error msg = "ERROR: #{msg}" $stdout.puts(color? ? @highline.color(msg, :red) : msg) else $stdout.puts(msg) end end |